Jobs processed, but not doing anything

Published 1 month ago by jack100

I am using jobs via database config and pushing jobs on the queue, which apparently works:

[2017-10-17 06:28:27] Processing: App\Jobs\SendReminderEmail
[2017-10-17 06:28:27] Processed:  App\Jobs\SendReminderEmail

But it looks like nothing is done by the job itself. I can't find anything in the log files or I used other methods to produce some actions, but nothing.

The job class I generated via artisan and looks like this:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class SendReminderEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        Log::info("Constructor");
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::info("Queue job run");
    }
}

Also, I do not see any action from the constructor? The jobs are visible in the database table. Falied jobs table is empty.

Thank you for your help.

Best Answer (As Selected By jack100)
jack100

OMG, so much time spend these days on this issue.

I installed Laravel 5.5 with: https://github.com/adr1enbe4udou1n/laravel-boilerplate

Can't get this to work at all. So many mistakes in this pack. :-(

I re-installed Laravel 5.4 with: https://github.com/Labs64/laravel-boilerplate

Same issue. Jobs are not working.

I installed Laravel 5.4. with: https://github.com/rappasoft/laravel-5-boilerplate

I was a nightmare getting everything together with php7.1 Finally, it works. Same setup as before. I guess the distribution of Labs64 Laravel Boilerplate I used is buggy. :-(

Choose your distribution wisely. SOLVED.

JamesMills

What are you using to run the queue? Have you restarted the queue worker since you edited SendReminderEmail?

jack100

I run a worker from bash. Nothing which is running permanently.

a00:/var/www/laravel-boilerplate$ php artisan queue:work --queue=myevents
[2017-10-17 08:31:39] Processing: App\Jobs\SendReminderEmail
[2017-10-17 08:31:39] Processed:  App\Jobs\SendReminderEmail

dlucian

I'm guessing the logging doesn't work. Have you tried a

die('here');

statement in the handle() method?

Also, check out .env option QUEUE_DRIVER, if it's set to null it's going to discard your handling code.

jack100

Queue driver is set to in .env:

QUEUE_DRIVER=database

Using "die" did not produce anything in logfile. I also tried to create a record or do a dump in the constructor, but nothing in the logs.

:-(

squibby

I have had this before and couldn't understand why it wouldnt log. Just stop the queue worker, and then check the logs the log info should be there. To check try doing something other than log in your job. E.g update a record or something. You will see it should work perfectly.

ftrillo

Are you dispatching the jobs on the default queue connection? If not, you need to pass the connection name to the queue:work command.

Also, check that the bash user running the queue:work has write permissions for the log files, or belongs to an user group that does.

jack100

@squibby I have additional code in the constructor, which makes a record in the DB. It does not produce any results. I see the jobs added to the DB table before being processed. So, I am pretty sure no additional worker is running.

jack100

@ftrillo As listed above I am using a specific queue and the worker works on this queue. As above the queue worker processes the job successfully. But no results in logs. I changed the owner of the log file to bash user, but no change.

ftrillo

You have to instantiate a job to dispatch it in the first place. If the constructor isn't running then there's something wrong before the queue even gets involved.

What's the code that dispatches the job?

jack100

@ftrillo Here the code to initiate the job.

        $job = (new SendReminderEmail())->onQueue('myevents');
        dispatch($job);
ftrillo

If you're running Laravel 5.5 try using the dispatch static method on the class instead of the helper. Like so:

SendReminderEmail::dispatch()->onQueue('myEvents');
jack100

@ftrillo I am running 5.4

jack100

OMG, so much time spend these days on this issue.

I installed Laravel 5.5 with: https://github.com/adr1enbe4udou1n/laravel-boilerplate

Can't get this to work at all. So many mistakes in this pack. :-(

I re-installed Laravel 5.4 with: https://github.com/Labs64/laravel-boilerplate

Same issue. Jobs are not working.

I installed Laravel 5.4. with: https://github.com/rappasoft/laravel-5-boilerplate

I was a nightmare getting everything together with php7.1 Finally, it works. Same setup as before. I guess the distribution of Labs64 Laravel Boilerplate I used is buggy. :-(

Choose your distribution wisely. SOLVED.

Please sign in or create an account to participate in this conversation.