Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rudenav opened this issue Dec 18, 2024 · 1 comment
Closed

Comments

@rudenav
Copy link
Contributor

rudenav commented Dec 18, 2024

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;
} 
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@rudenav rudenav closed this as completed Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants