问题描述
有没有人能够在 Rails 4.2 中获得预定的工作?
Has anyone been able to get scheduled jobs to work in Rails 4.2?
我正在使用 resque,并且我正在尝试使用 resque-scheduler 来安排作业.我有一个已加载并运行调度程序的计划,甚至看起来它正在运行作业,但它没有做任何事情.
I am using resque, and I am attempting to use resque-scheduler to schedule jobs. I have a schedule that get loaded and the scheduler runs, and even looks like it is running the jobs but it doesn't do anything.
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Starting
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Loading Schedule
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Scheduling friends
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Schedules Loaded
resque-scheduler: [INFO] 2014-09-16T01:54:55-07:00: queueing FriendsJob (friends)
我可以将这样的作业排入队列并得到处理.
I can enqueue jobs like this and they get processed.
TestJob.enqueue(params[:id])
我在工作日志中得到这个输出
and I get this output in the worker log
got: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])
** [01:24:01 2014-09-16] 54841: resque-1.25.2: Processing default since 1410855841 [ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper]
** [01:24:01 2014-09-16] 54841: Running before_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])]
** [01:24:01 2014-09-16] 54841: resque-1.25.2: Forked 54882 at 1410855841
** [01:24:01 2014-09-16] 54882: Running after_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])]
Hello World!!
** [01:24:01 2014-09-16] 54882: done: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])
但是当我尝试安排工作时,看起来他们正在排队,但他们没有做任何事情.
But when I try to schedule a job, it looks like the are getting enqueue but they well not doing anything.
这是schedule.yml
Here is the schedule.yml
friends:
every: "30s"
queue: "friends"
class: "FriendsJob"
args: 8
description: "Friends jobs scheduler"
这是预定作业的输出.
** [01:23:36 2014-09-16] 54841: got: (Job{friends} | FriendsJob | [8])
** [01:23:36 2014-09-16] 54841: resque-1.25.2: Processing friends since 1410855816 [FriendsJob]
** [01:23:36 2014-09-16] 54841: Running before_fork hooks with [(Job{friends} | FriendsJob | [8])]
** [01:23:36 2014-09-16] 54841: resque-1.25.2: Forked 54880 at 1410855816
** [01:23:36 2014-09-16] 54880: Running after_fork hooks with [(Job{friends} | FriendsJob | [8])]
** [01:23:36 2014-09-16] 54880: done: (Job{friends} | FriendsJob | [8])
阅读本文后 http://dev.mikamai.com/post/96343027199/rails-4-2-new-gems-active-job-and-global-id我怀疑它与 ActiveJob 和 GlobalId 有关.
After reading this http://dev.mikamai.com/post/96343027199/rails-4-2-new-gems-active-job-and-global-id I am suspecting it has something to do with ActiveJob and GlobalId.
看看入队的差异
** [01:24:01 2014-09-16] 54841: Running before_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])]
vs 预定
** [01:23:36 2014-09-16] 54841: Running before_fork hooks with [(Job{friends} | FriendsJob | [8])]
工作本身是通过
rails g job <JobName>
它们看起来像这样:
class TestJob < ActiveJob::Base
queue_as :default
def perform(friend_id)
friend = Friend.find(friend_id)
name = friend.name.swapcase
puts "Hello World!!"
end
end
class FriendsJob < ActiveJob::Base
queue_as :friends
def perform(friend_id)
friend = Friend.find(friend_id)
name = friend.name.swapcase
puts "Hello World!!"
end
end
对此的任何帮助将不胜感激,并提前致谢.
Any help with this will be greatly appreciated and thanks in advance.
********* 更新 *********
********* UPDATE *********
我已经删除了 action_job railtie,我只使用 Resque 和 Resque-Scheduler,并且预定的作业现在正在运行.所以这似乎与 ActionJob/GlobalId 有关.我在 rails 项目中打开了一个问题.希望他们能尽快修复它.
I've removed the action_job railtie and I am using Resque and Resque-Scheduler only, and scheduled jobs are working now. So this does seems to be related to ActionJob/GlobalId. I've open an issue in the rails project. Hopefully, they will fix it soon.
****** 第二次更新 *********我得到了这方面的更新.在 ActiveJob 代码库中工作的 Cristianbica 曾说过这一点.到目前为止,我们还没有考虑过重复性工作,我们不支持这一点,因为没有外部 gem 没有任何适配器支持这一点.然而,这是一个非常好的功能,但我认为我们无法及时完成4.2. 另外我不确定它是否适合包含在 rails 中"
****** SECOND UPDATE ********* I got an update on this. Cristianbica who works in the ActiveJob codebase said this. "We haven't thought at recurring jobs so far and we don't support this as none of the adapters support this without an external gem. However this is a very nice feature but I don't think we can make it in time for 4.2. Also I'm not sure it will suitable to be included in rails"
推荐答案
https://github.com/JustinAiken/active_scheduler 是一个将一个包裹到另一个中的宝石
https://github.com/JustinAiken/active_scheduler is a gem that wraps the one into the other
这篇关于Resque-Scheduler 不能与 Rails 4.2 中的 ActiveJob 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2