Framework: [5.1] [5.2] Redis Queue: Jobs are ending up in the queue without a $payload['job'] value.

Created on 22 Dec 2015  路  10Comments  路  Source: laravel/framework

This is then causing the queue to crash because in /Jobs/Job.php resolveAndFire() and failed() methods both look for the 'job' value. It's undefined so the job never ends up as a failed job.

I've verified looking at the list in redis directly that there is a "job" simply with an ID and attempts values:

"{\"id\":\"2XB76hubeCDCRqP74lsB326oftfwMmsY\",\"attempts\":81441}"

As you can see, this is being retried repeatedly despite ---tries being set to 3.

I'm not able to work out how these payloads are ending up there without a job field, which is clearly the root cause. However it would be useful if the failed() method at least could handle this undefined index. I'm sure this might be clearer to someone with more experience with the Queue code.

I'm pretty certain the jobs that are missing the 'job' index are being added via $this->dispatch() method in the controller as opposed to the older Queue::push(), that we've been using for longer reliably.

Also using the same redis database for cache + sessions, though we've not had any problems before. This started soon after we started using the $this->dispatch() method in a controller with a

bug

Most helpful comment

I'm newbie , so apologize me if is not a correct practice to write on a closed bug , i faced the same issue as described , but i finally make it work! , the problem seems when attaching kind of files , datatype out of primitive types, need to be encoded in base64 , and then be decoded just when data is "gone thorough the closure context" . Here my working dirty example :

$pdf = base64_encode($this->generatePdf()); 

Mail::queue($this->bladeEmailTemplate, $this->emailArrayData, function ($message) use ($pdf, 
$emailConfig) {
            $message->from('emailFromAddress');
            $message->subject('emailSubjectText');
            $message->to('emailToAddress');
            $message->attachData(base64_decode($pdf), name.pdf');
});

Hope this helps others !

All 10 comments

What Laravel version please.

Using "laravel/framework": "5.1.*" in composer.json

Thanks.

After reviewing this, I don't think it's a bug. Looks like you have old formatted jobs in the queue from a previous version, maybe 4.2 or something.

I'm unable to replicate this issue.

If you're able to provide very short replication instructions on 5.1, please send a new issue.

It's extremely unlikely we had old formatted jobs, we upgraded to 5.1 a long time ago now. There has to be another reason that some jobs were able to get into the queue with an ID but no $payload['job'] value. If I can reliably reproduce I will open another issue.

I have encountered this problem, and finally what is the solution?
The problem is occasional.

I faced the same issue. I am not that much sure, but one possible reason to such a problem can be that after the job serialized into the queue, you changed the name of the class, or did something similar to a property of the job and now the job cannot get unseriazlied because the class does not exists any more.

I'm newbie , so apologize me if is not a correct practice to write on a closed bug , i faced the same issue as described , but i finally make it work! , the problem seems when attaching kind of files , datatype out of primitive types, need to be encoded in base64 , and then be decoded just when data is "gone thorough the closure context" . Here my working dirty example :

$pdf = base64_encode($this->generatePdf()); 

Mail::queue($this->bladeEmailTemplate, $this->emailArrayData, function ($message) use ($pdf, 
$emailConfig) {
            $message->from('emailFromAddress');
            $message->subject('emailSubjectText');
            $message->to('emailToAddress');
            $message->attachData(base64_decode($pdf), name.pdf');
});

Hope this helps others !

Was this page helpful?
0 / 5 - 0 ratings