计划作业
commit信息:Add the precision that the interval should be in seconds (useful to know when not using ActiveSupport shorthands) | 提交者:qortex | 提交时间:2020-07-24 | 版本:d0e9f58
Sidekiq允许你安排作业执行的时间。你可以使用perform_in(interval_in_seconds, *args)
或者 perform_at(timestamp, *args)
而不是标准的 perform_async(*args)
:
MyWorker.perform_in(3.hours, 'mike', 1)
MyWorker.perform_at(3.hours.from_now, 'mike', 1)
例如,如果你想在用户注册之后三小时发给他们一个邮件,这将非常有用。排队之前的计划作业以便立即执行。
时区
Sidekiq的调度与时区无关。Sidekiq在时间戳参数上调用.to_f
,这能避免了时区混乱。了解详情,请查看这些issue。
检测新作业
Sidekiq的调度程序并不精确。它默认大约每5秒检测一次计划作业。(在Sidekiq 5.1之前是15秒)。你可以调整这个间隔。
Sidekiq.configure_server do |config|
config.average_scheduled_poll_interval = 15
end
周期作业
Sidekiq 商业版支持周期作业。其他的第三方gem也有类似功能。