Skip to content

Commit

Permalink
improve: reduce redundant concurrencies for popping jobs in queue worker
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Jan 27, 2025
1 parent d92a07f commit 9346d85
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/queue/src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,16 @@ public function daemon(string $connectionName, string $queue, WorkerOptions $opt
}

// First, we will attempt to get the next job off of the queue.
// Then, we can fire off this job. If there are no jobs,
// Then, we can fire off this job in coroutine. If there are no jobs,
// we will need to sleep the worker so no more jobs are processed
// until they should be processed.
$job = null;
$concurrent->create(function () use ($connectionName, $queue, $options, &$job, &$jobsProcessed) {
$job = $this->getNextJob(
$this->manager->connection($connectionName),
$queue
);
if ($job) {
++$jobsProcessed;
$this->runJob($job, $connectionName, $options);
}
});
$job = $this->getNextJob(
$this->manager->connection($connectionName),
$queue
);
if ($job) {
$concurrent->create(fn () => ++$jobsProcessed && $this->runJob($job, $connectionName, $options));
}

if ($job && $options->rest > 0) {
$this->sleep($options->rest);
Expand Down

0 comments on commit 9346d85

Please sign in to comment.