Skip to content

Queue Worker: firing the JobPopped event when $popCallbacks returns null #53959

@rudenav

Description

@rudenav

Laravel Version

11.x

PHP Version

8.3

Database Driver & Version

No response

Description

When $popCallbacks is assigned to the Illuminate\Queue\Worker class and it returns null the JobPopped event is fired with $job value null

Steps To Reproduce

Illuminate\Queue\Worker::$popCallbacks['test'] = function($popJobCallback, $queue) {
return null;
}

  1. queue:work --name=test
  2. listen for the event JobPopped

Fix:

In the class Illuminate\Queue\Worker method getNextJob
Replace:

if (isset(static::$popCallbacks[$this->name])) {
    return tap(
        (static::$popCallbacks[$this->name])($popJobCallback, $queue),
        fn ($job) => $this->raiseAfterJobPopEvent($connection->getConnectionName(), $job)
    );
} 

with:

if (isset(static::$popCallbacks[$this->name])) {
    if (! is_null($job = (static::$popCallbacks[$this->name])($popJobCallback, $queue))) {
        $this->raiseAfterJobPopEvent($connection->getConnectionName(), $job);
    }

    return $job;
} 

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