Event and Queue Debugging

Apr 26, 2017 laravel queue event debug
Coming back to the event that sends emails for a personal project, it came to the point to re-test the event and expectedly it didn’t work. It’s harder to find the issue with queues as they don’t print the stack trace in the browser, as it runs in the background and even worse is having the event work the night before.

The error
First the event did not fire. My code was

event( new SignUpEmailOrganiser($santa, $eventObj, $santaConfirmationObj) );

I did try to use Event::fire but that didn’t work either. having spent some time on the front-end, it was time to look at the Laravel 5.3 documentation, it seems that i was passing an email method into the event function. I am not sure why it worked previously but the event function takes an event object

event( new SantaSignUp($santa, $eventObj, $santaConfirmationObj) );

At some point I also received an error with the jobs table regarding a value passed to the ‘attempts’ column being out of range which was strange. But it seems after this the error did not turn up again instead what happened was the app was still using an old cached file that was pointing to the incorrect location of the email blade file.

php artisan cache:clear

Clearing the application cache immediately fixed this.

Debugging tips.
The fastest way to debug a queue is to check the laravel log. It can be found under the /storage/logs directory. Here it prints the stack trace making it very clear what the error is and you’re able to follow the point where the errors occurred. Use it.

Re-testing a failed job
Whatever the process is to trigger the event. You don’t want to have to sign up forms every time you want the event triggered, if you want to test the queue. If you want to test the event you may have to sign up but to easily re-qeuue a job that was failed, you can use the following commands

First find the relevant job in the jobs table with

php artisan queue:failed

Locate the ID number and use that as the argument for the command

php artisan queue:retry

If you found the following info helpful, I'm happy to accept any donations of the following cryptocurrencies.

  • Bitcoin - 17DTiPExzP9StqveW428acEyB4mVMfKbiK
  • Ethereum - 0x87B8307FD20dc90cc05c94905Ec593134D32B6FF
  • Litecoin - LZMiz5U5sVq9doMLYE3gfLJrxCQDKuyCmU
  • Neo - AXv71WB38ajc1KUUEnxQKhynLLPc4BapVb