26 lines
812 B
PHP
26 lines
812 B
PHP
<?php
|
|
|
|
namespace App\Console;
|
|
|
|
use App\Models\ProvisioningRun;
|
|
use App\Provisioning\Jobs\AdvanceRunJob;
|
|
|
|
/**
|
|
* Scheduler tick (every minute): dispatch an advance job for every run that is
|
|
* running/waiting and due. Immediate dispatch on advance handles the fast path;
|
|
* this catches waiting/retrying runs and anything a crashed worker left behind.
|
|
*/
|
|
class TickProvisioning
|
|
{
|
|
public function __invoke(): void
|
|
{
|
|
ProvisioningRun::query()
|
|
->whereIn('status', [ProvisioningRun::STATUS_RUNNING, ProvisioningRun::STATUS_WAITING])
|
|
->where(function ($q) {
|
|
$q->whereNull('next_attempt_at')->orWhere('next_attempt_at', '<=', now());
|
|
})
|
|
->get()
|
|
->each(fn (ProvisioningRun $run) => AdvanceRunJob::dispatch($run->uuid));
|
|
}
|
|
}
|