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
192 193 194 195 196 197 198 |
# File 'lib/delayed/recurring_job.rb', line 192 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
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/delayed/recurring_job.rb', line 157 def jobs( = {}) = .with_indifferent_access # Construct dynamic query with 'job_matching_param' if present query = {'$or' => [{handler: /--- !ruby\/object:#{name}[\s+]/}, {handler: /--- !ruby\/object:#{name}$/}]} if [:job_matching_param].present? matching_key = [:job_matching_param] matching_value = [matching_key] matching_yaml = yaml_quote(matching_value) query = {'$and' => [query, handler: /#{matching_key}: #{matching_yaml}/]} end ::Delayed::Job.where(query) end |
#priority(priority = nil) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/delayed/recurring_job.rb', line 140 def priority(priority = nil) if priority.nil? @priority else @priority = priority end end |
#queue(*args) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/delayed/recurring_job.rb', line 148 def queue(*args) if args.length == 0 @queue else @queue = args.first end end |
#run_at(*times) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/delayed/recurring_job.rb', line 111 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
124 125 126 127 128 129 130 |
# File 'lib/delayed/recurring_job.rb', line 124 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).
178 179 180 |
# File 'lib/delayed/recurring_job.rb', line 178 def schedule( = {}) schedule!() unless scheduled?() end |
#schedule!(options = {}) ⇒ Object
182 183 184 185 186 |
# File 'lib/delayed/recurring_job.rb', line 182 def schedule!( = {}) return unless Delayed::Worker.delay_jobs unschedule() new.schedule!() end |
#scheduled?(options = {}) ⇒ Boolean
188 189 190 |
# File 'lib/delayed/recurring_job.rb', line 188 def scheduled?( = {}) jobs().count > 0 end |
#timezone(zone = nil) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/delayed/recurring_job.rb', line 132 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)
172 173 174 |
# File 'lib/delayed/recurring_job.rb', line 172 def unschedule( = {}) jobs().each{|j| j.destroy} end |