ruby on rails 4 - Rufus-scheduler not working on nginx/passenger in environment production -


i’m having problems rufus-scheduler not working in environment production, i’m tried adding: passenger_spawn_method direct; passenger_min_instances 1; rails_app_spawner_idle_time 0; in nginx config still not solve problem.

my code using rufus-scheduler:

    def expired_at=(datetime)     datetime = time.zone.parse(datetime) if datetime.class == string && !datetime.empty?     if expired_at       expired_at     else       if datetime > time.zone.now         scheduler = rufus::scheduler.new         begin           scheduler.at datetime.strftime("%y/%m/%d %h:%m")             self.update_attributes(:finished => true )           end         rescue => ex           rails.logger.info ex.message           rails.logger.info ex.backtrace         end       else         self[:finished] = true       end       self[:expired_at] = datetime     end   end 

i'm stuck in problem. appreciated, thank in advance.

i'm using:

  • nginx: 1.8.0
  • fusion passenger: 5.0.10
  • rufus-scheduler: 3.1.3

i cannot solve problem, because you're not describing happens (or doesn't happen).

but, can tell code poorly thought.

your expired_at= method, guess it's model method. so, realize initializing rufus-scheduler instance each time calling expired_at=?

you'd better try

def expired_at=(datetime)    datetime = time.zone.parse(datetime) \     if datetime.class == string && !datetime.empty?    if expired_at     expired_at   else     if datetime > time.zone.now       begin         rufus::scheduler.singleton.at datetime.strftime("%y/%m/%d %h:%m")           self.update_attributes(:finished => true )         end       rescue => ex         rails.logger.info ex.message         rails.logger.info ex.backtrace       end     else       self[:finished] = true     end     self[:expired_at] = datetime   end end 

it relies on rufus::scheduler.singleton you'll use single rufus-scheduler instance. alternative start scheduler in initializer , leverage model. perhaps you'll forced since passenger won't keep thread created incoming request around. you'll have test (and learn).

but, change way of thinking , have single rufus-scheduler job wakes up, twice day, , queries models expired_at value , set finished true if necessary. if go way, use whenever: wrap query+update in rake task , let whenever (in fact system's crond) call twice day (advantage: don't have tweak passenger settings).

good luck!


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -