Resque-Scheduler无法在Rails 4.2中使用ActiveJob [英] Resque-Scheduler not working with ActiveJob in Rails 4.2

查看:125
本文介绍了Resque-Scheduler无法在Rails 4.2中使用ActiveJob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能获得预定的工作以在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"])]

已安排

** [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栏目,并且仅使用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.另外,我不确定是否适合将其包含在导轨中.

****** 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆