mercredi 12 janvier 2022

Unique Jobs in Laravel 5.2

I have a legacy application in laravel 5.2 and we use queues to process jobs. We observed that the queue can sometimes get too many jobs which leads to duplicate jobs getting dispatched because the previous jobs don't complete processing and the cron that dispatches such jobs runs again and ends up dispatching them over and over.

A simple solution would be to make these jobs unique which would be a very simple change if it were laravel 8. However, we're in laravel 5.2 territory so i'll have to implement unique jobs myself. Or if someone could suggest a better alternative?

Also, if you were to implement unique jobs yourself, how would you do it? The approach I'm thinking is:

Add a unique key for the job to the cache or a database table (implying a lock is attained) Clear the entry once the job is processed (lock released) Before dispatching the job, check if the key exists in the cache or not (lock can be attained or not)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire