Tuesday, 15 February 2011

ruby on rails - schedule rufus-scheduler onto worker dyno on heroku -



ruby on rails - schedule rufus-scheduler onto worker dyno on heroku -

i'd utilize rufus-scheduler have background task run. have worker dyno sidekiq , ideally schedule onto process. testing rufus-scheduler per documentation @ https://github.com/jmettraux/rufus-scheduler#so-rails

require 'rufus-scheduler' # let's utilize rufus-scheduler singleton # s = rufus::scheduler.singleton # stupid recurrent task... # s.every '1s' rails.logger.info "hello, it's #{time.now}" end

it comes out on both web , worker , i'd utilize worker process. how accomplish that?

sample output is:

2014-10-17t00:30:29.382689+00:00 app[web.1]: hello, it's 2014-10-17 00:30:29 +0000 2014-10-17t00:30:29.609192+00:00 app[worker.1]: hello, it's 2014-10-17 00:30:29 +0000

something next it:

if running_on_worker_process? # have implement 1 yourself. require 'rufus-scheduler' s = rufus::scheduler.singleton s.every '1d' rails.logger.info "taking out garbage..." end end

beware worker process (dyno?) going sleep (and scheduler it).

edit 1

tip: can utilize $dyno variable (https://devcenter.heroku.com/articles/dynos#local-environment-variables) identify dyno you're on.

if env['dyno'].match(/^worker\./) # ... end

ruby-on-rails heroku rufus-scheduler

No comments:

Post a Comment