Marek Adam
Marek Adam

Reputation: 13

Laravel Jobs - dynamic queues, delay between jobs

I have dilemma with implementation for Laravel Jobs - queues. I need make queue for shops entities - orders and products synchronization to other api (limited requests for minute). But I need that shops don't influence each other.

E.g. I have shop that need synchronize 1000 products. But in same time there is other shop with product that needed to be synchronized too.

  1. I need set delay for synchronization because of limited API req/min (this API have limitation by shop so 2 shops can process at once). How can I set some delay between job for first shop from example to process this 1000 products. E.g. API is limited 10req/1min (10req/60s). How can I set delay 6s between each job?
  2. I need avoid that second shop must wait while first shop will process this 1000 products.

What I try:

for delay: sleep([6s]) in Laravel Job handle (not working) because when I get 3 products jobs at same time, I cannot send him with this delay between each other. I try set delay([6s]) for Laravel Job, but same result too.

for avoid waiting: I tought about dynamic creation queues (for each shop separated) but I don't know if Laravel Jobs makes smoething like this possible.

Any idea how implement this situation. Thank you.

Upvotes: 0

Views: 1162

Answers (1)

antare74
antare74

Reputation: 94

Try using carbon, Eg:

$dateTime = "2022-08-12 12:00:00";
$carbonDate = Carbon::parse($date);
JobsPublishArticle::dispatch()->delay($dateTime);

Or

$dateTime = Carbon::now()->addSeconds(10); // you can use minutes, hours, etc too.
JobsPublishArticle::dispatch()->delay($dateTime);

Upvotes: 0

Related Questions