Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job doesn't run from static schedule #613

Closed
Babdus opened this issue May 28, 2017 · 14 comments
Closed

Job doesn't run from static schedule #613

Babdus opened this issue May 28, 2017 · 14 comments

Comments

@Babdus
Copy link

Babdus commented May 28, 2017

Hello,
I have read similar issues but nothing helped me.

Here is my lib/tasks/resque.rake file:

require 'resque/tasks'
require 'resque/scheduler/tasks'

namespace :resque do
  task :setup do
    require 'resque'
    require 'resque-scheduler'
  end
  task :setup_schedule => :setup do
    require 'resque-scheduler'
    Resque.schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yml")
  end
  task :scheduler => :setup_schedule
end

And resque_schedule.yml:

TestCronJob:
  every: '1m'
  class: TestCronJob
  queue: test
  description: "This job puts something every 1 minute"

And this is test_cron_job.rb:

class TestCronJob < ApplicationJob
  queue_as :test

  def perform
    puts 'something'
  end

end

In command line:

QUEUE=* bundle exec rake environment resque:work&

and

rake environment resque:scheduler

The job is being queued, but never run (I tested on several jobs, not just putting something):

resque-scheduler: [INFO] 2017-05-29T02:36:07+04:00: Starting
resque-scheduler: [INFO] 2017-05-29T02:36:07+04:00: Loading Schedule
resque-scheduler: [INFO] 2017-05-29T02:36:07+04:00: Scheduling TestCronJob 
resque-scheduler: [INFO] 2017-05-29T02:36:07+04:00: Schedules Loaded
resque-scheduler: [INFO] 2017-05-29T02:37:07+04:00: queueing TestCronJob (TestCronJob)
resque-scheduler: [INFO] 2017-05-29T02:38:07+04:00: queueing TestCronJob (TestCronJob)

Can anybody help me find out what is going wrong?

@carsonreinke
Copy link
Contributor

@Babdus Any chance this is using a different Redis instance or database? Could you try running resque:work with the VERBOSE=1

@Babdus
Copy link
Author

Babdus commented May 31, 2017

I have only one Redis instance with one database, so it can't be the case.
After running resque:work with the VERBOSE=1 here is the output:

*** Starting worker main
*** Running before_first_fork hooks
*** got: (Job{test} | TestCronJob | [])
*** Running before_fork hooks with [(Job{test} | TestCronJob | [])]
*** Running after_fork hooks with [(Job{test} | TestCronJob | [])]
*** done: (Job{test} | TestCronJob | [])

But nothing ever happened. (I've put code in this TestCronJob for retrying failed jobs)

@carsonreinke
Copy link
Contributor

This issue is unrelated to resque-scheduler, as clearly the job is being queued into the right place and resque is running it.

With that said, I think your problem is ApplicationJob defines self.perform, but in your TestCronJob that defines the instance method perform, not the class level, so try changing that to just def self.perform and it should work.

@sevos
Copy link

sevos commented Jun 18, 2017

I have the same issue. It seems that resque-schedule does not play with ActiveJob adapter. When I enqueue job manually, I get the following output:

*** got: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"BrainTickJob", "job_id"=>"a4abb078-fc2e-4ce9-bdd0-d781861d0815", "queue_name"=>"default", "priority"=>nil, "arguments"=>[], "executions"=>0, "locale"=>"en"}])

vs resque-schedule from static schedule:

*** got: (Job{default} | BrainTickJob | [])

@canted
Copy link

canted commented Jul 19, 2017

I'm seeing the same issue. I did get it to work with these settings, as an ugly workaround

job = HelloJob.new
Resque.schedule = {
  hello: {
    every: "10s",
    class: "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper",
    queue: :default,
    args: {"job_class"=>job.class.to_s, "job_id"=>job.job_id, "queue_name"=>job.queue_name, "priority"=>nil, "arguments"=>[], "locale"=>"en"},
    description: "Hello World"
  },
}

@carsonreinke
Copy link
Contributor

@sevos Any chance you can run that with the VERBOSE on? There should be no reason why either should not work.

@TimFletcher
Copy link

I was having the exact same problem as @sevos and @Babdus. Using the following worked for me:

CopyClickStatsJob:
  every: '10s'
  class: ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
  queue: default
  description: "Migrate click stats from the write table to the read table"
  args:
    job_class:  CopyClickStatsJob
    queue_name: default
    arguments: []

@mickaelmagniez
Copy link

@TimFletcher solution work for me too

@glebm
Copy link

glebm commented Sep 4, 2018

resque-scheduler still doesn't work with ActiveJob out of the box (despite the issue being closed). Resque itself does work with ActiveJob out of the box.

Update: There is a gem that works around the compatibility issue: https://github.com/JustinAiken/active_scheduler

@jpcuevaslavin
Copy link

@TimFletcher solution worked for me too. Thanks!

@stuartluscombe
Copy link

The solution from @TimFletcher worked for me also.

I tried the active-scheduler gem but I ran in to issues with resque-scheduler not initialising correctly.

@MartinSugasti
Copy link

@TimFletcher your code worked for me. Thanks.

@justrenato
Copy link

@TimFletcher worked for me too. Cant believe that's still happenning ;-;

@jronallo
Copy link

If instead of a scheduled job you're using enqueue_at_with_queue you can do something like this which includes arguments:

time_to_send = Time.now + 120
Resque.enqueue_at_with_queue(
        :mail_updates,
       time_to_send,
        ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper,
        {
          job_class: SubscriptionsJob,
          job_id: SecureRandom.uuid,
          queue_name: :mail_updates,
          priority: nil,
          arguments: [{arg1: "value", another_arg: "value2"}],
          locale: 'en'
        }
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests