Laravel如何在多租户应用程序中为每个租户管理不同的队列? [英] Laravel how can we manage different queue for each tenant in multi tenant application?

查看:147
本文介绍了Laravel如何在多租户应用程序中为每个租户管理不同的队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我有多租户申请.
  2. 每个租户都有多个操作(sync_customers,sync_metafileds,install_code,verify_code等),我需要为此执行API调用.
  3. API调用每秒限制2个调用(一分钟内最多可以调用41个).

案例1

  • i.假设一个租户有10,000个客户.同步过程是 正在运行.
  • 同时,租户添加对install_code的请求. (install_code需要最少16个API调用.)
  • 现在我可以根据优先级停止sync_customers并启动install_code或仅将所有呼叫添加到队列中.
  • i. suppose one tenant has 10,000 customers. And syncing process is running.
  • At the same time tenant add request for install_code. (install_code needs min 16 API calls.)
  • Now either i can stop sync_customers and start install_code based on priority or just add all calls to queue.

我需要的是

  1. 针对不同租户的不同队列.
  2. 队列需要优先.
  3. 如果在任何队列进程之间都存在更高优先级的任务,请先完成它,然后继续执行未决任务.
  4. 如果没有其他待处理任务,则仅优化服务器资源并关闭该队列.

我正在将AWS和laravel v5.x与php版本7.x一起使用

i am using AWS and laravel v5.x with php version 7.x

希望每个人都明白我的意思.

Hope every one got my point.

谢谢.

推荐答案

我创建了一个自定义命令 queue:work_stores,参数为{user_id}.

I created one custom command queue:work_stores with argument {user_id}.

哪个运行队列:使用参数--once = true

Which run queue:work with arguments --once=true

$this->call('queue:work', [
  "--once" => true,
  "database"
]);

一个标志,用于跟踪当前队列:work_stores是否正在运行.

One flag which track if the current queue:work_stores is running or not.

检查完整代码 https://gist.github.com/little-isaac/a6d70c82f372406f827fb3b399745c8e

这篇关于Laravel如何在多租户应用程序中为每个租户管理不同的队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆