Module: Delayed::RecurringJob::ClassMethods

Defined in:
lib/delayed/recurring_job.rb

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/delayed/recurring_job.rb', line 189

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

#jobsObject

Show all jobs for this schedule



164
165
166
# File 'lib/delayed/recurring_job.rb', line 164

def jobs
  ::Delayed::Job.where("(handler LIKE ?) OR (handler LIKE ?)", "--- !ruby/object:#{name} %", "--- !ruby/object:#{name}\n%")
end

#priority(priority = nil) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/delayed/recurring_job.rb', line 147

def priority(priority = nil)
  if priority.nil?
    @priority
  else
    @priority = priority
  end
end

#queue(*args) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/delayed/recurring_job.rb', line 155

def queue(*args)
  if args.length == 0
    @queue
  else
    @queue = args.first
  end
end

#run_at(*times) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/delayed/recurring_job.rb', line 118

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



131
132
133
134
135
136
137
# File 'lib/delayed/recurring_job.rb', line 131

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).



175
176
177
# File 'lib/delayed/recurring_job.rb', line 175

def schedule(options = {})
  schedule!(options) unless scheduled?
end

#schedule!(options = {}) ⇒ Object



179
180
181
182
183
# File 'lib/delayed/recurring_job.rb', line 179

def schedule!(options = {})
  return unless Delayed::Worker.delay_jobs
  unschedule
  new.schedule!(options)
end

#scheduled?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/delayed/recurring_job.rb', line 185

def scheduled?
  jobs.count > 0
end

#timezone(zone = nil) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/delayed/recurring_job.rb', line 139

def timezone(zone = nil)
  if zone.nil?
    @tz
  else
    @tz = zone
  end
end

#unscheduleObject

Remove all jobs for this schedule (Stop the schedule)



169
170
171
# File 'lib/delayed/recurring_job.rb', line 169

def unschedule
  jobs.each{|j| j.destroy}
end