Home > Back-end >  laravel 5.7 job instance create but not execute
laravel 5.7 job instance create but not execute

Time:07-18

I have created jobs for video converting and updating in database in Laravel 5.7. All created jobs work correctly but any new job I am create in that only instance create but not execute. I have created one test email job with log entry.

My env file changes: .env

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

In config folder: queue.php

'default' => env('QUEUE_CONNECTION', 'sync'),

'connections' => [

        'sync' => [
            'driver' => 'sync',
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'default',
            'retry_after' => 400000,
        ],

Job called by cron job custom command: TestEmail.php

MatchSendEmail::dispatch()->onQueue('queue_test');

My test mail job: MatchSendEmail.php

namespace App\Jobs;
use Mail;
use App\Mail\EmailTest;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        app('log')->info('supervisor send mail for all construct->');
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        app('log')->info('supervisor send mail for all handle');
        $email = new EmailTest();
        Mail::to(['******@gmail.com', 'ravi@****.com'])->send($email);
        app('log')->info('supervisor send mail for all handle1');
    }
}

I have used supervisor for background process and below is configuration file:

[program:queue_test]

process_name=%(program_name)s_%(process_num)02d

command=php /home/web1/******.com/htdocs/artisan queue:work --tries=10 --sleep=5

autostart=true

autorestart=true

user=web1

numprocs=20

redirect_stderr=true

stdout_logfile=/home/web1/******.com/htdocs/storage/logs/queue_test.log

Only job instance creates but not execute, please guide me how this issue resolve.

CodePudding user response:

As your QUEUE_CONNECTION is set to database you need to run the below command to make the database table

php artisan queue:table
 
php artisan migrate

Then you need to start the worker by running the below command

php artisan queue:work --timeout=30

Otherwise, for testing, you can set the QUEUE_CONNECTION to sync and run the job synchronously or you can call this below method to run the job without interacting with any queue

MatchSendEmail::dispatchNow()

CodePudding user response:

when you run the queue you have to specify the queue you are dispatching on when not using the default.

--queue=queue_test

So insert that into your supervisor and this line should be.

command=php /home/web1/******.com/htdocs/artisan queue:work --tries=10 --sleep=5 --queue=queue_test
  • Related