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

Schedule not being reloaded when starting Rails app #35

Closed
shedd opened this issue Jun 30, 2014 · 10 comments · Fixed by #37
Closed

Schedule not being reloaded when starting Rails app #35

shedd opened this issue Jun 30, 2014 · 10 comments · Fixed by #37

Comments

@shedd
Copy link
Contributor

shedd commented Jun 30, 2014

I'm seeing an issue where restarting the Rails app does not reload the schedule.

Following the README example, I have an initializer that loads config/schedule.yml

require 'sidekiq/scheduler'
Sidekiq.schedule = YAML.load_file(File.expand_path('../../../config/schedule.yml', __FILE__))

If the following is my schedule.yml

vagrant@precise64:/vagrant$ cat config/schedule.yml
############################################################################
# Defines the schedule of recurring Sidekiq jobs
# See https://github.com/Moove-it/sidekiq-scheduler for more information
############################################################################

# run, every minute, the job to look for delayed orders
queue_delayed_order_notifications:
  every: ["1m"]
  class: DelayedOrderNotifications
  description: "This job looks for delayed orders and triggers the appropriate notifications"

It loads fine:

vagrant@precise64:/vagrant$ bundle exec rails c
Loading development environment (Rails 4.1.2)
[1] pry(main)> Sidekiq.schedule
=> {"queue_delayed_order_notifications"=>
  {"every"=>["1m"],
   "class"=>"DelayedOrderNotifications",
   "description"=>"This job looks for delayed orders and triggers the appropriate notifications"}}

However, if I change the schedule - so changing from 1m to 1h:

vagrant@precise64:/vagrant$ cat config/schedule.yml
############################################################################
# Defines the schedule of recurring Sidekiq jobs
# See https://github.com/Moove-it/sidekiq-scheduler for more information
############################################################################

# run, every minute, the job to look for delayed orders
queue_delayed_order_notifications:
  every: ["1h"]
  class: DelayedOrderNotifications
  description: "This job looks for delayed orders and triggers the appropriate notifications"

Then I reload Rails:

vagrant@precise64:/vagrant$ bundle exec rails c
Loading development environment (Rails 4.1.2)
[1] pry(main)> Sidekiq.schedule
=> {"queue_delayed_order_notifications"=>
  {"every"=>["1m"],
   "class"=>"DelayedOrderNotifications",
   "description"=>"This job looks for delayed orders and triggers the appropriate notifications"}}

The schedule has not changed. It's still 1m in Sidekiq, even though I've completely reloaded the app.

In fact, in my Vagrant development environment, the only thing that I found to reload the schedule is actually to reboot the VM.

Is this expected? I've used Resque scheduler before, so I'm expecting behavior similar to that - with Resque scheduler, the schedule was loaded fresh every time the Rails app was restarted.

@adrian-gomez
Copy link
Contributor

The schedule should we reloaded fresh everytime you start your app, ill try to reproduce this and comment back.

What version of sidekiq-scheduler are you using?

@shedd
Copy link
Contributor Author

shedd commented Jul 4, 2014

@adrian-gomez awesome, thanks. would appreciate any pointers.

I'm using the latest - v1.0.

@adrian-gomez
Copy link
Contributor

I'm seeing the same issue but only with the rails console, if i start the server or sidekiq the schedules are loaded properly. Can you confirm this?

I'll look into this issue to find out what is causing this behavior.

@shedd
Copy link
Contributor Author

shedd commented Jul 4, 2014

@adrian-gomez I was able to confirm that I just print out Sidekiq.scheduler into a view and then fire up bundle exec rails s, then change the schedule, restart bundle exec rails s, the output of the view does change. So yes, it does appear to be the console.

@adrian-gomez
Copy link
Contributor

There also seems like modifying the initializer (config/initializers/sidekiq_scheduler.rb) causes the schedule to reload :S

This is really strange.

@shedd
Copy link
Contributor Author

shedd commented Jul 4, 2014

@adrian-gomez I think it's the Rails spring preloader.

vagrant@precise64:/vagrant$ spring status
Spring is not running.
vagrant@precise64:/vagrant$ rails c
Loading development environment (Rails 4.1.4)
[1] pry(main)> puts Sidekiq.schedule
{"queue_delayed_order_notifications"=>{"every"=>["1m"], "class"=>"DelayedOrderNotifications", "description"=>"This job looks for delayed orders and triggers the appropriate notifications"}}
=> nil
[2] pry(main)> exit
vagrant@precise64:/vagrant$ spring status
Spring is running:

 4759 spring server | vagrant | started 25 secs ago
 4763 spring app    | vagrant | started 25 secs ago | development mode                
vagrant@precise64:/vagrant$ spring stop
Spring stopped.


[ Change the schedule from 1m to 1h ]


vagrant@precise64:/vagrant$ rails c
Loading development environment (Rails 4.1.4)
[1] pry(main)> puts Sidekiq.schedule
{"queue_delayed_order_notifications"=>{"every"=>["1h"], "class"=>"DelayedOrderNotifications", "description"=>"This job looks for delayed orders and triggers the appropriate notifications"}}
=> nil

By manually stopping Spring, it seems to work.

@adrian-gomez
Copy link
Contributor

Ok i'll close this issue if you are ok with it.

I haven't looked into spring at all, maybe there is a workaround for this that i'm not aware of.

@shedd
Copy link
Contributor Author

shedd commented Jul 4, 2014

Sure, I'm fine with closing this now that I understand what's going on.

Apparently, Spring reloads the initializers if they are changed, but not if they are unmodified, so that's what's happening.

It appears to be possible to tell Spring to do things before loading: https://github.com/rails/spring#running-code-before-forking

So this could potentially be used to clean this up.

It might be worth putting a note in the README about this, in case anyone else encounters this.

@adrian-gomez
Copy link
Contributor

I'll great if you could add that comment to in the README :D

@shedd
Copy link
Contributor Author

shedd commented Jul 5, 2014

PR submitted :)

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

Successfully merging a pull request may close this issue.

2 participants