Module: Delayed::RecurringJob::ClassMethods
- Defined in:
- lib/delayed/recurring_job.rb
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
-
#jobs ⇒ Object
Show all jobs for this schedule.
- #priority(priority = nil) ⇒ Object
- #queue(*args) ⇒ Object
- #run_at(*times) ⇒ Object
- #run_every(interval = nil) ⇒ Object
-
#schedule(options = {}) ⇒ Object
Main interface to start this schedule (adds it to the jobs table).
- #schedule!(options = {}) ⇒ Object
- #scheduled? ⇒ Boolean
- #timezone(zone = nil) ⇒ Object
-
#unschedule ⇒ Object
Remove all jobs for this schedule (Stop the schedule).
Instance Method Details
#inherited(subclass) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/delayed/recurring_job.rb', line 186 def inherited(subclass) [:@run_at, :@run_interval, :@tz, :@priority].each do |var| next unless instance_variable_defined? var subclass.instance_variable_set var, self.instance_variable_get(var) subclass.instance_variable_set "#{var}_inherited", true end end |
#jobs ⇒ Object
Show all jobs for this schedule
160 161 162 163 |
# File 'lib/delayed/recurring_job.rb', line 160 def jobs ::Delayed::Job.any_of({:handler => Regexp.new(".*--- !ruby/object:#{name}.*")}) # ::Delayed::Job.where("(handler LIKE ?) OR (handler LIKE ?)", "--- !ruby/object:#{name} %", "--- !ruby/object:#{name}\n%") end |
#priority(priority = nil) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/delayed/recurring_job.rb', line 143 def priority(priority = nil) if priority.nil? @priority else @priority = priority end end |
#queue(*args) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/delayed/recurring_job.rb', line 151 def queue(*args) if args.length == 0 @queue else @queue = args.first end end |
#run_at(*times) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/delayed/recurring_job.rb', line 114 def run_at(*times) if times.length == 0 @run_at || run_every.from_now else if @run_at_inherited @run_at = [] @run_at_inherited = nil end @run_at ||= [] @run_at.concat times end end |
#run_every(interval = nil) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/delayed/recurring_job.rb', line 127 def run_every(interval = nil) if interval.nil? @run_interval || 1.hour else @run_interval = interval end end |
#schedule(options = {}) ⇒ Object
Main interface to start this schedule (adds it to the jobs table). Pass in a time to run the first job (nil runs the first job at run_interval from now).
172 173 174 |
# File 'lib/delayed/recurring_job.rb', line 172 def schedule( = {}) schedule!() unless scheduled? end |
#schedule!(options = {}) ⇒ Object
176 177 178 179 180 |
# File 'lib/delayed/recurring_job.rb', line 176 def schedule!( = {}) return unless Delayed::Worker.delay_jobs unschedule new.schedule!() end |
#scheduled? ⇒ Boolean
182 183 184 |
# File 'lib/delayed/recurring_job.rb', line 182 def scheduled? jobs.count > 0 end |
#timezone(zone = nil) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/delayed/recurring_job.rb', line 135 def timezone(zone = nil) if zone.nil? @tz else @tz = zone end end |
#unschedule ⇒ Object
Remove all jobs for this schedule (Stop the schedule)
166 167 168 |
# File 'lib/delayed/recurring_job.rb', line 166 def unschedule jobs.each{|j| j.destroy} end |