Delaying a Laravel Artisan command in a queue from code

I am running the Artisan command from the controller in my Laravel application. As indicated in the docs , you can put the following queue:

Artisan::queue('email:send', [
    'user' => 1, '--queue' => 'default'
]);

This takes care of the queue logic and, in my case, sends the job to Redis, where it is processed almost immediately.

I want to postpone the work. You can usually do this when calling the queue command as follows:

$job = (new SendReminderEmail($user))->delay(60);

$this->dispatch($job);

Is there a way to join these features so that I can delay the Artisan team for 5 minutes? I suggested that there is an easy way to set it aside.

If not, I could create another Job class to stand between my controller and the Artisan command, which I could queue in the usual way and hold, and then make this call my Artisan command. But this seems like a really confusing way to make it work. Is there a better way to delay an Artisan team in line?

thanks

+4
source share
2 answers

Since the console core uses "push" for the command queue, this is not possible with laravel 5.3 and earlier.

However, you can make a stretch request for the framework to implement a “later” call in the kernel, which can simply go to the “later” function in the queue.

, .

. "":

Mail::later(5, 'emails.welcome', $data, function ($message) {
    //
});

. https://laravel.com/docs/5.2/mail#queueing-mail .

+1

, , . , , , , ..

0

Source: https://habr.com/ru/post/1623963/


All Articles