有没有人能够在Rails 4.2中获得预定的工作?
我正在使用resque,我正在尝试使用resque-scheduler来安排作业.我有一个计划加载和调度程序运行,甚至看起来它正在运行作业但它没有做任何事情.
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)
我可以将这样的工作排队,然后进行处理.
TestJob.enqueue(params[:id])
我在工作日志中得到了这个输出
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"])
但是当我尝试安排一份工作时,看起来好像已经入队,但他们没有做任何事情.
这是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有关.
看看排队的差异
** [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
它们看起来像这样:
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
对此的任何帮助将非常感谢并提前感谢.
*********更新*********
我已经删除了action_job铁路,我只使用Resque和Resque-Scheduler,而且预定的工作现在正在运行.所以这似乎与ActionJob/GlobalId有关.我在rails项目中打开了一个问题.希望他们能尽快解决.
******第二次更新*********我得到了更新.在ActiveJob代码库工作的Cristianbica说这个."到目前为止,我们还没有考虑到重复工作,我们不支持这一点,因为没有外部宝石,没有一个适配器支持这个.但这是一个非常好的功能,但我认为我们不能及时做到4.2.另外我不确定它是否适合包含在轨道中"