Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- The lost-lease schema check caches its result for 60 seconds by the framework
clock instead of PHP's `time()`, so a frozen test clock holds the window and
query-count tests no longer see an extra schema query on slow runs.

## 2.34.0 - 2026-11-19

2.34.0 adds one migration (#1231): workflow tasks gain `lost_lease_count` and
Expand Down
12 changes: 9 additions & 3 deletions src/V2/Support/WorkflowTaskLeaseLoss.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Log;
use InvalidArgumentException;
use Workflow\V2\Enums\TaskStatus;
Expand Down Expand Up @@ -359,10 +360,15 @@ private static function hasColumn(Model $model, string $column, bool $fresh = fa
{
$key = $model->getConnectionName() . '|' . $model->getTable() . '|' . $column;
$cached = self::$schemas[$key] ?? null;
$now = time();
// The framework clock, so a frozen test clock holds the window.
$now = Date::now()->getTimestamp();

if (! $fresh && $cached !== null && $now - $cached['checked_at'] < self::SCHEMA_RECHECK_SECONDS) {
return $cached['tracked'];
if (! $fresh && $cached !== null) {
$elapsed = $now - $cached['checked_at'];

if ($elapsed >= 0 && $elapsed < self::SCHEMA_RECHECK_SECONDS) {
return $cached['tracked'];
}
}

$tracked = $model->getConnection()
Expand Down
31 changes: 31 additions & 0 deletions tests/Feature/V2/V2WorkflowTaskLostLeaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,37 @@ public function testASummaryColumnRollbackDegradesSummaryWrites(): void
}
}

public function testTheSchemaCheckWindowFollowsTheFrameworkClock(): void
{
$this->travelTo(now()->startOfSecond());
$this->assertTrue(WorkflowTaskLeaseLoss::summaryTracked(true));
$queries = 0;
DB::listen(static function () use (&$queries): void {
$queries++;
});

// A frozen clock holds the cached check however long the test runs.
$this->travel(59)
->seconds();
$this->assertTrue(WorkflowTaskLeaseLoss::summaryTracked());
$this->assertSame(0, $queries);

$this->travel(1)
->seconds();
$this->assertTrue(WorkflowTaskLeaseLoss::summaryTracked());
$this->assertGreaterThan(0, $queries);

// A clock moved backwards re-checks once, then holds again.
$queries = 0;
$this->travel(-120)
->seconds();
$this->assertTrue(WorkflowTaskLeaseLoss::summaryTracked());
$this->assertGreaterThan(0, $queries);
$queries = 0;
$this->assertTrue(WorkflowTaskLeaseLoss::summaryTracked());
$this->assertSame(0, $queries);
}

protected function startQueueWorkersAutomatically(): bool
{
return false;
Expand Down