19 August 2020

Laravel - Redis - Que - Failed Job

 Laravel has capability to send task/job to worker. Means when the request coming from client/browser, certain task/code can be pass to be process later by worker. This will enable laravel to complete the http response faster, without need to wait for that certain code to finish process.


In laravel, this can be done by creating a class that implements ShoudQueue.

class ProcessPodcast implements ShouldQueue

ProcessPodcast::dispatch()   will tell Laravel to queue the job in redis(this is one of the option), then worker will retrieve the job from redis.

If there is error during the job execution, it will be put in table failed_jobs.

We can request Laravel to resubmit this fail jobs to redis again by:
php artisan queue:retry all


To check jobs list in redis:

$ redis-cli
127.0.0.1:6379> keys *
From figure above, we can tell the pending jobs in redis is 131,093.



To check failed jobs:
mysql> select (*) from failed_jobs;






No comments:

Post a Comment

Terima kasih