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

Load resque_scheduler #117

Open
mrvovanness opened this issue Aug 13, 2015 · 3 comments
Open

Load resque_scheduler #117

mrvovanness opened this issue Aug 13, 2015 · 3 comments

Comments

@mrvovanness
Copy link

I am trying to test dynamic schedules. As is suggested I included in my Gemfile:

gem 'resque-scheduler', require: 'resque_scheduler'

but I get error can not load such file -- resque_scheduler. I tried to include in environments/test.rb, but with same effect. I tried also to write simple test to be sure that gem is working:

describe Survey do
  let!(:survey) { create(:survey) } 
  before do
    ResqueSpec.reset!
  end

  it 'works' do
    survey.update(title: 'Good')
    expect(SendEmailsJob).to have_schedule_size_of(1)
  end
end

update action triggers scheduling(via after_save callback)

And I had output:

ExpectationNotMetError: expected that SendEmailsJob would have 1 s
cheduled entries, but got 0 instead>>

And web interface of Resque shows me that I created new schedule. I need some clues what is going on.

@leshill
Copy link
Owner

leshill commented Aug 13, 2015

Hi @mrvovanness,

Try removing the require option from your Gemfile. The latest README of resque-scheduler indicates that it is not needed. If that works, ping back and I will update the resque_spec README.

@mrvovanness
Copy link
Author

Hello @leshill!

I removed the require option and that works. But whenever I trigger scheduling in my test it shows me that my schedule size is 0, but actually in development and production mode scheduling works perfect. For example, when I create new instance of `Survey' this triggers the creation of new schedule via callback:

#...
after_save :schedule_send_emails
def schedule_send_emails
  config[:every] = '1w'
  name = "send_emails_for_survey_#{id}"
  config[:class] = 'SendEmailsJob'
  config[:queue] = 'send_emails'
  config[:persist] = true
  config[:args] = id
  Resque.set_schedule(name, config)
end

but when I test this:

it 'create schedule on #save' do
    survey.save
    expect(SendEmailsJob).to have_schedule_size_of(1)
  end

I have error expected that SendEmailsJob would have 1 s cheduled entries, but got 0 instead
I have no idea what I am doing wrong
For now I just end up requesting test Redis database:

  it 'create schedule on #save' do
    survey.save
    expect(Resque.schedule_persisted?("send_emails_for_survey_#{survey.id}")).to be true
  end

@leshill
Copy link
Owner

leshill commented Aug 16, 2015

Hi @mrvovanness,

The code is not covering that method from the resque-scheduler API:

Resque.set_schedule(name, config)

This is not supported yet. A PR to do so would be welcome.

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

2 participants