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
2 changes: 1 addition & 1 deletion .github/workflows/migration_numbering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/Console/Command/Work.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
'<comment>RETRY %d/%d</comment> (next at %s)',
$currentTries + 1,
$maxRetries,
$job->available_at->format('H:i:s')
$retried->available_at->format('H:i:s')
);
} else {
$logMessage = '<info>FAILED</info>';
Expand Down Expand Up @@ -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) {
Expand Down
Loading