module Delayed::RecurringJob::ClassMethods
Public Instance Methods
inherited(subclass)
click to toggle source
# 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 = {})
click to toggle source
Show all jobs for this schedule
# File lib/delayed/recurring_job.rb, line 167 def jobs(options = {}) options = options.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 options[:job_matching_param].present? matching_key = options[:job_matching_param] matching_value = options[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)
click to toggle source
# File lib/delayed/recurring_job.rb, line 150 def priority(priority = nil) if priority.nil? @priority else @priority = priority end end
queue(*args)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
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).
# File lib/delayed/recurring_job.rb, line 190 def schedule(options = {}) schedule!(options) unless scheduled?(options) end
schedule!(options = {})
click to toggle source
# File lib/delayed/recurring_job.rb, line 194 def schedule!(options = {}) return unless Delayed::Worker.delay_jobs unschedule(options) new.schedule!(options.merge(new_instance: true)) end
scheduled?(options = {})
click to toggle source
# File lib/delayed/recurring_job.rb, line 200 def scheduled?(options = {}) jobs(options).count > 0 end
timezone(zone = nil)
click to toggle source
# File lib/delayed/recurring_job.rb, line 142 def timezone(zone = nil) if zone.nil? @tz else @tz = zone end end
unschedule(options = {})
click to toggle source
Remove all jobs for this schedule (Stop the schedule)
# File lib/delayed/recurring_job.rb, line 184 def unschedule(options = {}) jobs(options).each{|j| j.destroy} end
Private Instance Methods
yaml_quote(value)
click to toggle source
# File lib/delayed/recurring_job.rb, line 213 def yaml_quote(value) # In order to ensure matching indentation, place the element inside a # two-level hash (the first level mimicking 'schedule_options', the second # for #{job_matching_param}), and strip out the leading "---\n:a:\n :a: " # but keep the trailing newline. ({a: {a: value}}).to_yaml[14..-1] end