Resque-Scheduler在Rails 4.2中不使用ActiveJob

lui*_*gal 7 ruby-on-rails resque ruby-on-rails-4 resque-scheduler rails-activejob

有没有人能够在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)
Run Code Online (Sandbox Code Playgroud)

我可以将这样的工作排队,然后进行处理.

TestJob.enqueue(params[:id])
Run Code Online (Sandbox Code Playgroud)

我在工作日志中得到了这个输出

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"])
Run Code Online (Sandbox Code Playgroud)

但是当我尝试安排一份工作时,看起来好像已经入队,但他们没有做任何事情.

这是schedule.yml

friends:
  every: "30s"
  queue: "friends"
  class: "FriendsJob"
  args: 8
  description: "Friends jobs scheduler"
Run Code Online (Sandbox Code Playgroud)

这是预定作业的输出.

** [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])
Run Code Online (Sandbox Code Playgroud)

在阅读了这篇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"])]
Run Code Online (Sandbox Code Playgroud)

vs预定

** [01:23:36 2014-09-16] 54841: Running before_fork hooks with [(Job{friends} | FriendsJob | [8])]
Run Code Online (Sandbox Code Playgroud)

这些工作本身就是通过

 rails g job <JobName>
Run Code Online (Sandbox Code Playgroud)

它们看起来像这样:

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
Run Code Online (Sandbox Code Playgroud)

对此的任何帮助将非常感谢并提前感谢.

*********更新*********

我已经删除了action_job铁路,我只使用Resque和Resque-Scheduler,而且预定的工作现在正在运行.所以这似乎与ActionJob/GlobalId有关.我在rails项目中打开了一个问题.希望他们能尽快解决.

******第二次更新*********我得到了更新.在ActiveJob代码库工作的Cristianbica说这个."到目前为止,我们还没有考虑到重复工作,我们不支持这一点,因为没有外部宝石,没有一个适配器支持这个.但这是一个非常好的功能,但我认为我们不能及时做到4.2.另外我不确定它是否适合包含在轨道中"

Jus*_*ken 5

https://github.com/JustinAiken/active_scheduler是一颗宝石,它将一个包裹在一起


Mar*_*lar 2

更新:2016 年 4 月 4 日 - 虽然以下答案对于当前版本的 Rails 来说仍然正确,但我现在使用 Justin 创建的 active_scheduler gem,如上面答案中所述:https ://stackoverflow.com/a/29155372/ 1299792

原始答案:如果您需要安排重复作业,请避免使用 ActiveJob。

路易斯提出的问题来看

由于我们目前不支持 ActiveJob 的重复作业,因此我们将关闭此功能。如果可以支持重复性工作,我将其视为单独的 gem 或在 Rails 5 中。功能请求和围绕它们的讨论通常在邮件列表中讨论(https://groups.google.com/forum/#!forum ) /rubyonrails-core)。作为您问题的解决方案@luismadrigal,我建议您使用 resque-scheduler 方式来完成重复性工作。

https://github.com/rails/rails/issues/16933#issuecomment-58945932

邮件列表中有关于创建 gem 的讨论,但我找不到任何进一步的信息。