Skip to content

RedisQueue::pop() has 2 issues #6366

@halaei

Description

@halaei

I am concerned about 2 issues in this code from RedisQueue.php:

public function pop($queue = null)
{
    $original = $queue ?: $this->default;
    $this->migrateAllExpiredJobs($queue = $this->getQueue($queue));
    $job = $this->redis->lpop($queue);
    if ( ! is_null($job))
    {
        $this->redis->zadd($queue.':reserved', $this->getTime() + 60, $job);
        return new RedisJob($this->container, $this, $job, $original);
    }
}
  1. Assume you pop a job and then something crashed. Then the job cab be lost for ever before getting reserved. I guess this can be handled with Redis scripts or transactions (but not sure).

  2. assume you run this command:

    php artisan queue:listen --timeout=120

This means you expect your job takes more than 1 min. Now if you have multiple listeners to the same queue (I don't see anybody told me I can't do that), then the job may get re-pushed by the execution of following line by another listener:

$this->migrateExpiredJobs($queue.':reserved', $queue);

I think it will be nice to replace that hard-coded 60 with something like $this->max_run_time + some_epsilon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions