【发布时间】:2017-02-11 09:50:59
【问题描述】:
我有一些计划任务使用真正的队列服务运行作业。
现在,我希望能够从仪表板手动运行这些任务,等待其执行,并在控制器操作中读取/处理其一些输出。典型的情况是当管理员想要手动重新加载一些统计信息时,可以将服务器停顿几秒钟。
有没有办法将 ActiveJob 适配器更改为“内联”以便做到这一点?如果可能的话,我还想阅读此作业生成的一些工件(可能是实例变量,或者performaction 的返回值)。
有什么办法吗?
示例作业
class TopLevelJob < ApplicationJob
def perform
some_iterator.each do
SomeNestedJob.rand.perform_later
# There are several types of sub-jobs that can be called
# Passing a flag param (perform vs perform_later) would be kind of annoying
end
end
module SomeNestedJob
class A < ApplicationJob;
def perform
# May in turn spawn an other job with perform_later
end
end
...
class Z < ApplicationJob; ...; end
def self.rand
[A..Z].sample
end
end
【问题讨论】:
标签: ruby-on-rails jobs ruby-on-rails-5 rails-activejob