简体   繁体   English

Laravel 作业 - 动态队列,作业之间的延迟

[英]Laravel Jobs - dynamic queues, delay between jobs

I have dilemma with implementation for Laravel Jobs - queues.我对 Laravel Jobs - queues 的实现进退两难。 I need make queue for shops entities - orders and products synchronization to other api (limited requests for minute).我需要为商店实体排队 -订单产品与其他 api 同步(分钟请求有限)。 But I need that shops don't influence each other.但我需要商店不要相互影响。

Eg I have shop that need synchronize 1000 products.例如,我有需要同步 1000 种产品的商店。 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) .由于 API req/min 有限,我需要设置同步延迟(此 API 受商店限制,因此可以同时处理 2 家商店) How can I set some delay between job for first shop from example to process this 1000 products.如何在第一家商店的工作之间设置一些延迟,例如处理这 1000 种产品。 Eg API is limited 10req/1min (10req/60s).例如 API 限制为 10req/1min (10req/60s)。 How can I set delay 6s between each job?如何在每个作业之间设置延迟 6s?
  2. I need avoid that second shop must wait while first shop will process this 1000 products.我需要避免第二家商店必须等待,而第一家商店将处理这 1000 种产品。

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.对于延迟: Laravel 中的sleep([6s])作业句柄(不工作)因为当我同时获得 3 个产品作业时,我无法在彼此之间以这种延迟发送他。 I try set delay([6s]) for Laravel Job, but same result too.我尝试为 Laravel 作业设置delay([6s]) ,但结果也相同。

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.为了避免等待:我对动态创建队列(每个商店分开)进行了讨论,但我不知道 Laravel Jobs 是否使这样的 smoeth 成为可能。

Any idea how implement this situation.知道如何实现这种情况。 Thank you.谢谢你。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM