Class: Rufus::Scheduler::CronJobQueue

Inherits:
JobQueue
  • Object
show all
Defined in:
lib/rufus/sc/jobqueues.rb

Overview

Tracking cron jobs.

Constant Summary

Constants inherited from JobQueue

JobQueue::JOB_TYPES

Instance Method Summary collapse

Methods inherited from JobQueue

#select, #size, #to_h, #unschedule

Constructor Details

#initializeCronJobQueue

Returns a new instance of CronJobQueue.



130
131
132
133
134
# File 'lib/rufus/sc/jobqueues.rb', line 130

def initialize

  super
  @last_cron_second = nil
end

Instance Method Details

#<<(job) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/rufus/sc/jobqueues.rb', line 150

def <<(job)

  @mutex.synchronize do
    delete(job.job_id)
    @jobs << job
  end
end

#trigger_matching_jobsObject



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/rufus/sc/jobqueues.rb', line 136

def trigger_matching_jobs

  now = Time.now

  return if now.sec == @last_cron_second
  @last_cron_second = now.sec
    #
    # ensuring the crons are checked within 1 second (not 1.2 second)

  jobs = @mutex.synchronize { @jobs.dup }

  jobs.each { |job| job.trigger_if_matches(now) }
end