lib/midget_jobs/scheduler.rb
# interval till next job or 0 if there is no job - meaning sleep for ever or till wakeup
interval till next job or 0 if there is no job - meaning sleep for ever or till wakeup
interval till next job or 0 if there is no job - meaning sleep for ever or till wakeup
def sleep_till_next_job
      most_current = MidgetJob.order(run_at: :asc).first
      if most_current
        Rails.logger.info "#{self.class.name}.#{__method__} (#{[most_current.run_at.to_f - Time.current.to_f, 0.001].max} sec) till #{most_current.serialized['job_class']}"
        sleep [most_current.run_at.to_f - Time.current.to_f, 0.001].max
      else
        Rails.logger.info "#{self.class.name}.#{__method__}(Thread.stop)"
        Thread.stop
      end
    end
def sleep_till_next_job most_current = MidgetJob . order ( run_at : :asc ) . first if most_current Rails . logger . info "#{self.class.name}.#{__method__} (#{[most_current.run_at.to_f - Time.current.to_f, 0.001].max} sec) till #{most_current.serialized['job_class']}" sleep [ most_current . run_at . to_f - Time . current . to_f , 0.001 ] . max else Rails . logger . info "#{self.class.name}.#{__method__}(Thread.stop)" Thread . stop end end
interval till next job or 0 if there is no job - meaning sleep for ever or till wakeup
interval till next job or 0 if there is no job - meaning sleep for ever or till wakeup