class ActiveJob::Cron::Clock

Attributes

schedules[R]

Public Instance Methods

gettime() click to toggle source

Returns the current time used by the clock.

# File lib/active_job/cron/clock.rb, line 30
def gettime
  ActiveJob::Cron.config.utc ? Time.now.utc : Time.now
end
schedule_for(job) click to toggle source

Get the schedule for ‘job`.

# File lib/active_job/cron/clock.rb, line 16
def schedule_for(job)
  if job.respond_to?(:schedule)
    job.schedule
  end
end
tick(time = gettime) click to toggle source

Tick a single clock.

# File lib/active_job/cron/clock.rb, line 23
def tick(time = gettime)
  ActiveJob::Cron.jobs.each do |job|
    ActiveJob::Cron.handler.dispatch(job, time)
  end
end

Private Instance Methods

loop!() click to toggle source
# File lib/active_job/cron/clock.rb, line 36
def loop!
  after([time { tick }, 0].max) do
    loop!
  end
rescue StandardError => e
  raise e
end
time() { || ... } click to toggle source
# File lib/active_job/cron/clock.rb, line 44
def time
  start = gettime
  yield
  ActiveJob::Cron.config.resolution - (gettime.to_f - start.to_f)
end