I have 4 methods: A, B1, B2, B3 and want to encapsulate their execution in separate jobs. A generates result that B uses so A must be finished before starting B, and if A fails don't start B. Also for performance reasons I don't want B1, B2, B3 to run concurrently, but sequential, start B2 when B1 is finished, but they don't share results so if some B fails, start other normally. I don't want any retry on fail, just one attempt for each. So execution order is A->B1->B2->B3.
In docs there is not much about synchronizing mechanisms, so it's not obvious how to implement this. I found Queue::after handler, which as I understand fires on every job end, how do you filter which job? By class if(is_a($event->job , 'JobAClass'))...?
https://laravel.com/docs/5.3/queues#job-events
Queue::after(function (JobProcessed $event) {
// $event->connectionName
// $event->job
// $event->job->payload()
});
If you see laravel has a priority system for queues so for the first issue that you had that you don't want simultaneous execution just set up one priority with only one worker.
And laravel will process one job one by one
If you want a1 and the b1 and then b2 you just need to say ok when a is done dispatch the job b1 and so one
It's possible to dispatch jobs inside jobs just use the dispatches jobs trait
For the case that b1 fails I suggest to capture the possible exceptions In the code so b2 can be executed
arasmit2453 said:
If you want a1 and the b1 and then b2 you just need to say ok when a is done dispatch the job b1 and so one
It's possible to dispatch jobs inside jobs just use the dispatches jobs trait
For the case that b1 fails I suggest to capture the possible exceptions In the code so b2 can be executed
This couples them. Can't i use after handler like I intended?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community