Could anyone get the scheduled tasks to work in Rails 4.2?
I am using resque and I am trying to use resque-scheduler to schedule tasks. I have a schedule that scheduler loads and starts, and it even looks like it starts tasks, but does nothing.
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 set tasks like this and they will be processed.
TestJob.enqueue(params[:id])
and I get this conclusion in the work 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 task, it looks like they are getting a queue, but they are not doing anything.
Here is the .yml schedule
friends: every: "30s" queue: "friends" class: "FriendsJob" args: 8 description: "Friends jobs scheduler"
Here is the result of a scheduled task.
** [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])
After reading this http://dev.mikamai.com/post/96343027199/rails-4-2-new-gems-active-job-and-global-id I suspect this has something to do with ActiveJob and GlobalId .
Take a look at the difference in line
** [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 planned
** [01:23:36 2014-09-16] 54841: Running before_fork hooks with [(Job{friends} | FriendsJob | [8])]
The tasks themselves were created through
rails g job <JobName>
They look like this:
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 would be greatly appreciated and in advance.
********* UPDATE *********
I removed the action_job railtie and I use only Resque and Resque-Scheduler, and scheduled tasks now work. So this is similar to ActionJob / GlobalId. I open a problem in a rails project. I hope they fix it soon.
****** SECOND UPDATE ********* I received an update about this. This was stated by Cristianbica, who works in the ActiveJob code base. βWe have not thought about repetitive work, and we do not support it, since none of the adapters supports it without an external gem. However, this is a very nice feature, but I donβt think we will be in time 4.2 Also Iβm not sure that it will be included in the rails "