Skip to content

ShouldBeUnique doesn't clear lock when job is finished. #37729

Closed
@rflatt-reassured

Description

@rflatt-reassured
  • Laravel Version: 8.47.0
  • PHP Version: 7.4.10
  • Horizon Version 5.7.9

Description:

ShouldBeUnique and ShouldBeUniqueUntilProcessing do not release lock unless a timeout is set, and then it only releases after the timeout has expired, not after the job has been processed.

Steps To Reproduce:

class ... implements ShouldQueue, ShouldBeUnique
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $userId;

    /**
     * The unique ID of the job.
     *
     * @return string
     */
    public function uniqueId()
    {
        return $this->userId;
    }    

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($userId)
    {
        $this->userId = $userId;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try {
            //call the stored proc to assign a lead:
            $assigned = \DB::select('CALL ...(' . $this->userId . ')');
            $data = [
                'Status' => 'success',
                'result_id' => $result[0]->id
            ];
            event(new BroadcastToUser($this->userId, 'event', $data));

        } catch (\Exception $e) {
            event(new BroadcastToUser($this->userId, 'event', ['Status' => 'error']));
        }
    }

The above job runs once for $this->userId, but then will never be added to the queue again, unless I remove ShouldBeUnique.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions