N
N
Nikolino2018-11-27 06:11:36
Laravel
Nikolino, 2018-11-27 06:11:36

How to call the same queue every N seconds?

calling the queue

Route::get('/', function () {
    $test = Test::find(1);
    App\Jobs\ChangeTestNumber::dispatch()->delay(15);
});

The queue is added to the table and the handle() method is executed
public function handle()
{
    $test = Test::find(1);
    $test->number = rand(1,540);
    $test->save();        
}

In handle I try to call the same queue again like this:
public function handle()
{
    $test = Test::find(1);
    $test->number = rand(1,1000);
    $test->save(); 
    self::dispatch()->delay(20);  
}

But the second and subsequent queues are not added to jobs, only the first one.
I'm doing a test task (already irrelevant, I'm doing it for myself). The question is:
Let's add a new field to the user - experience We need to create a function in which:
The user will be retrieved and stored in the variable $user = User::find(1) 

Next, the function displays experience
Parallel to the operation of the function 
 The
asynchronous method changes the experience to a random number every few seconds 

the first function is once again displayed after a period of time user experience. What will this conclusion be? 


Tell me how else can I make the execution of some method every N seconds using queues? Or not using them. Cronjobs are executed once a minute, of course you can somehow get confused with sleeps, but maybe there is a better option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2018-11-27
@Nikolino

But the second and subsequent queues are not added to jobs
This is where I broke my brain. Usually jobs are queued, not queued in jobs...
https://github.com/laravel/framework/blob/5.7/src/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question