0

I am using Laravel 6 and I have an external API. I want to limit the requests to this API to one request per 10 seconds.This API is called inside a job. How can I achieve this?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
xnor
  • 11
  • 1
  • 5

1 Answers1

0

With Laravel 6 you can delay the job. So you do like:

JobClass::dispatch($payload)->delay(now()->addSeconds(10));

You may throttle a given type of job to only run 1 time every 10 seconds. So to impose this throttle it requires redis and you do like:

Redis::throttle('key')->allow(1)->every(10)->then(function () {

You can set time to the failed jobs so it takes time.

/**
 * The number of seconds to wait before retrying the job.
 *
 * @var int
 */
public $retryAfter = 10;
francisco
  • 1,387
  • 2
  • 12
  • 23