ActiveJob 队列限制

ActiveJob queue limiting

看起来任务简单明了:我需要限制可以同时执行的作业数量,这样我的服务器就不会崩溃。但是 google 是沉默的,也许我做错了什么?请赐教?

我使用标准异步适配器。

不建议在生产中使用默认 rails 异步适配器,尤其是对于每天重启一次的 heroku dyno。

For enqueuing and executing jobs in production you need to set up a queuing backend, that is to say you need to decide for a 3rd-party queuing library that Rails should use. Rails itself only provides an in-process queuing system, which only keeps the jobs in RAM. If the process crashes or the machine is reset, then all outstanding jobs are lost with the default async backend. This may be fine for smaller apps or non-critical jobs, but most production apps will need to pick a persistent backend.

有很多支持的适配器可供选择,例如:

  • Sidekiq
  • 重新请求
  • 作业延迟

上手很容易,他们提供了清晰的说明和示例。