Module: Delayed::RecurringJob::ClassMethods
- Defined in:
- lib/delayed/recurring_job.rb
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
-
#jobs(options = {}) ⇒ 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?(options = {}) ⇒ Boolean
- #timezone(zone = nil) ⇒ Object
-
#unschedule(options = {}) ⇒ Object
Remove all jobs for this schedule (Stop the schedule).
Instance Method Details
#inherited(subclass) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/delayed/recurring_job.rb', line 204 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(options = {}) ⇒ Object
Show all jobs for this schedule
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/delayed/recurring_job.rb', line 167 def jobs( = {}) = .with_indifferent_access # Construct dynamic query with 'job_matching_param' if present query = ["((handler LIKE ?) OR (handler LIKE ?))", "--- !ruby/object:#{name} %", "--- !ruby/object:#{name}\n%"] if [:job_matching_param].present? matching_key = [:job_matching_param] matching_value = [matching_key] matching_yaml = yaml_quote(matching_value) query[0] = "#{query[0]} AND handler LIKE ?" query << "%#{matching_key}: #{matching_yaml}%" end ::Delayed::Job.where(query) end |
#priority(priority = nil) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/delayed/recurring_job.rb', line 150 def priority(priority = nil) if priority.nil? @priority else @priority = priority end end |
#queue(*args) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/delayed/recurring_job.rb', line 158 def queue(*args) if args.length == 0 @queue else @queue = args.first end end |
#run_at(*times) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/delayed/recurring_job.rb', line 121 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
134 135 136 137 138 139 140 |
# File 'lib/delayed/recurring_job.rb', line 134 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).
190 191 192 |
# File 'lib/delayed/recurring_job.rb', line 190 def schedule( = {}) schedule!() unless scheduled?() end |
#schedule!(options = {}) ⇒ Object
194 195 196 197 198 |
# File 'lib/delayed/recurring_job.rb', line 194 def schedule!( = {}) return unless Delayed::Worker.delay_jobs unschedule() new.schedule!(.merge(new_instance: true)) end |
#scheduled?(options = {}) ⇒ Boolean
200 201 202 |
# File 'lib/delayed/recurring_job.rb', line 200 def scheduled?( = {}) jobs().count > 0 end |
#timezone(zone = nil) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/delayed/recurring_job.rb', line 142 def timezone(zone = nil) if zone.nil? @tz else @tz = zone end end |
#unschedule(options = {}) ⇒ Object
Remove all jobs for this schedule (Stop the schedule)
184 185 186 |
# File 'lib/delayed/recurring_job.rb', line 184 def unschedule( = {}) jobs().each{|j| j.destroy} end |