diff --git a/.github/workflows/migration_numbering.yml b/.github/workflows/migration_numbering.yml index d2801df..cc4e109 100644 --- a/.github/workflows/migration_numbering.yml +++ b/.github/workflows/migration_numbering.yml @@ -38,7 +38,7 @@ jobs: # The check itself ships with nails/common - name: Install Composer dependencies - run: COMPOSER_ROOT_VERSION=dev-develop composer install --no-interaction --prefer-dist + run: COMPOSER_ROOT_VERSION=dev-feature/pre-new-admin composer install --no-interaction --prefer-dist # The branch being merged into is not a counterpart to compare against - name: Check migration numbering diff --git a/src/Console/Command/Work.php b/src/Console/Command/Work.php index 37c75c4..0d4a241 100644 --- a/src/Console/Command/Work.php +++ b/src/Console/Command/Work.php @@ -26,6 +26,11 @@ class Work extends Base implements SignalableCommandInterface { + /** + * The longest, in milliseconds, an idle worker will wait between polls + */ + protected const MAX_WAIT_TIME = 5000; + protected Logger $logger; protected Database $database; protected Manager $manager; @@ -250,12 +255,12 @@ protected function startEventLoop(array $queues): void $maxRetries = max(0, (int) $job->task::getMaxRetries()); $currentTries = (int) ($job->attempts ?? 0); if ($currentTries < $maxRetries) { - $this->manager->retryJob($job, $e); + $retried = $this->manager->retryJob($job, $e); $logMessage = sprintf( 'RETRY %d/%d (next at %s)', $currentTries + 1, $maxRetries, - $job->available_at->format('H:i:s') + $retried->available_at->format('H:i:s') ); } else { $logMessage = 'FAILED'; @@ -283,6 +288,12 @@ protected function startEventLoop(array $queues): void usleep($chunk * 1000); $remainingMs -= $chunk; } + + // Back off while idle; the wait resets once a job has been run + $waitTime = min( + $waitTime * 2, + max(static::MAX_WAIT_TIME, Config::get('QUEUE_WORKER_WAIT_TIME', 500)) + ); } } catch (Throwable $e) {