I am working on an app that requires fetching data from a third-party server and that server allows max 1 request per seconds.
Now, all request send as job and I am
I am rate limiting a job que to max out at 100 jobs per day. I chose to use the 'delay' feature.
Job Class
Sample delay without much context...
$que = config(ServiceProvider::SHORT_NAME . '.job-queue');
$preceeding_job = Job::whereQueue($que['name'])
->orderBy('available_at', 'DESC')
->first();
if(!empty($preceeding_job)){
$available = $preceeding_job->available_at;
}else{
$available = Carbon::now();
}
ProbeGoogle::dispatch($obj)
->onConnection($que['connection'])
->onQueue($que['name'])
->delay($available->addMinutes(15));
Note that completed jobs are removed from the jobs table, so you need another means of tracking them and a bit more logic to calculate $available. I use https://github.com/imTigger/laravel-job-status for that. For this example, I went with simple logic. It will either fire 15 min after the last job in the queue, or 15 min from now. That helps pace things out just in case the last job fired and disappeared 2 seconds ago.