I'm aware of this thread: A cron job for rails: best practices?, but there's no mention of ActiveJob. My motivation to do it with ActiveJob is because it's built-in in Rails and here's an excerpt from its docs:
我知道这个帖子:rails的一个cron工作:最佳实践?但是没有提到ActiveJob。我使用ActiveJob做的动机是因为它内置在Rails中,这里是它的文档的摘录:
"These jobs can be everything from regularly scheduled clean-ups, to billing charges, to mailings."
“这些工作可以是定期清理,计费和邮寄等所有工作。”
How do I create a daily job (cron-like) in Rails ActiveJob? Since I don't see the example to run a regularly scheduled job in its docs.
如何在Rails ActiveJob中创建日常工作(类似cron)?因为我没有看到在其文档中运行定期计划作业的示例。
Or should I stick with the whenever
gem?
或者我应该坚持每当宝石?
2 个解决方案
#1
8
Stick with the whenever
gem or similar gem e.g. chrono
, clockwork
, rufus-scheduler
.
坚持每当宝石或类似的宝石,例如计时,发条,rufus-scheduler。
What you're reading in the ActiveJob documentation is a bit confusing, because it could seem as if ActiveJob may be able handle the responsibility of regular scheduling. What the documentation should say IMHO is that the jobs are regularly scheduled by some other system or tool.
您在ActiveJob文档中阅读的内容有点令人困惑,因为看起来好像ActiveJob可能能够处理常规调度的责任。文档应该说恕我直言,工作是由其他一些系统或工具定期安排的。
So, ActiveJob is about queued jobs?
那么,ActiveJob是关于排队的工作?
Yes, it's about Rails providing a standard interface for adding a job to a queue, and calling a perform method. ActiveJob provides the method interfaces that enable adapters for many job-processing queues, backends, immediate runners, etc.
是的,它是关于Rails提供标准接口,用于将作业添加到队列,并调用perform方法。 ActiveJob提供方法接口,为许多作业处理队列,后端,直接运行程序等启用适配器。
#2
5
It's working for me:
它对我有用:
every 1.day, at: '9:36 am' do
runner 'SomeJob.perform_later'
end
I'm using whenever
and ActiveJob
我随时都在使用ActiveJob
#1
8
Stick with the whenever
gem or similar gem e.g. chrono
, clockwork
, rufus-scheduler
.
坚持每当宝石或类似的宝石,例如计时,发条,rufus-scheduler。
What you're reading in the ActiveJob documentation is a bit confusing, because it could seem as if ActiveJob may be able handle the responsibility of regular scheduling. What the documentation should say IMHO is that the jobs are regularly scheduled by some other system or tool.
您在ActiveJob文档中阅读的内容有点令人困惑,因为看起来好像ActiveJob可能能够处理常规调度的责任。文档应该说恕我直言,工作是由其他一些系统或工具定期安排的。
So, ActiveJob is about queued jobs?
那么,ActiveJob是关于排队的工作?
Yes, it's about Rails providing a standard interface for adding a job to a queue, and calling a perform method. ActiveJob provides the method interfaces that enable adapters for many job-processing queues, backends, immediate runners, etc.
是的,它是关于Rails提供标准接口,用于将作业添加到队列,并调用perform方法。 ActiveJob提供方法接口,为许多作业处理队列,后端,直接运行程序等启用适配器。
#2
5
It's working for me:
它对我有用:
every 1.day, at: '9:36 am' do
runner 'SomeJob.perform_later'
end
I'm using whenever
and ActiveJob
我随时都在使用ActiveJob