README.md in rufus-scheduler-3.8.0 vs README.md in rufus-scheduler-3.8.1
- old
+ new
@@ -1647,26 +1647,30 @@
#
# config/initializers/scheduler.rb
require 'rufus-scheduler'
-s = Rufus::Scheduler.singleton
+return if defined?(Rails::Console) || Rails.env.test? || File.split($PROGRAM_NAME).last == 'rake'
+ #
+ # do not schedule when Rails is run from its console, for a test/spec, or
+ # from a Rake task
-return if defined?(Rails::Console) || Rails.env.test? || File.split($0).last == 'rake'
# return if $PROGRAM_NAME.include?('spring')
+ #
# see https://github.com/jmettraux/rufus-scheduler/issues/186
-# do not schedule when Rails is run from its console, for a test/spec, or
-# from a Rake task
+s = Rufus::Scheduler.singleton
s.every '1m' do
Rails.logger.info "hello, it's #{Time.now}"
Rails.logger.flush
end
```
+(Beware later version of Rails where Spring takes care pre-running the initializers. Running `spring stop` or disabling Spring might be necessary in some cases to see changes to initializers being taken into account.)
+
### rails server -d
(Written in reply to https://github.com/jmettraux/rufus-scheduler/issues/165 )
There is the handy `rails server -d` that starts a development Rails as a daemon. The annoying thing is that the scheduler as seen above is started in the main process that then gets forked and daemonized. The rufus-scheduler thread (and any other thread) gets lost, no scheduling happens.
@@ -1678,9 +1682,12 @@
* https://www.mikeperham.com/2014/09/22/dont-daemonize-your-daemons/
* https://www.mikeperham.com/2014/07/07/use-runit/
If, anyway, you need something like `rails server -d`, why not try `bundle exec unicorn -D` instead? In my (limited) experience, it worked out of the box (well, had to add `gem 'unicorn'` to `Gemfile` first).
+### executor / reloader
+
+You might benefit from wraping your scheduled code in the executor or reloader. Read more here: https://guides.rubyonrails.org/threading_and_code_execution.html
## support
see [getting help](#getting-help) above.