Class: Delayed::RepeatingJob
Instance Method Summary collapse
-
#repeat(message = "", backtrace = []) ⇒ Object
Repeat the job in the future.
- #repeats_every ⇒ Object
- #repeats_every=(time_span) ⇒ Object
-
#run(max_run_time = 500) ⇒ Object
I always repeat! Try to run job.
- #total_runs ⇒ Object
- #total_runs=(value) ⇒ Object
Instance Method Details
#repeat(message = "", backtrace = []) ⇒ Object
Repeat the job in the future.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/delayed/repeating_job.rb', line 48 def repeat(="", backtrace = []) unless .blank? self.last_error = %Q|#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}: #{}\n#{backtrace.join("\n")} "\n#{self.last_error}| if self.failed_at = Time.now self.attempts += 1 else self.failed_at = nil self.attempts = 0 end while(run_at <= Time.now) do self.run_at += repeats_every end self.unlock self.total_runs += 1 save! reload .blank? end |
#repeats_every ⇒ Object
4 5 6 |
# File 'lib/delayed/repeating_job.rb', line 4 def repeats_every (@repeats_every ||= payload_object.repeats_every || 1.minutes) rescue 1.minutes end |
#repeats_every=(time_span) ⇒ Object
8 9 10 11 |
# File 'lib/delayed/repeating_job.rb', line 8 def repeats_every=(time_span) payload_object.repeats_every = time_span if payload_object.respond_to?(:repeats_every) @repeats_every = time_span end |
#run(max_run_time = 500) ⇒ Object
I always repeat! Try to run job. Returns true/false (work done/work failed)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/delayed/repeating_job.rb', line 27 def run(max_run_time=500) runtime = Benchmark.realtime do #FIXME: I don't like timeout ... #Timeout.timeout(max_run_time.to_i) { invoke_job } invoke_job end # TODO: warn if runtime > max_run_time ? logger.info "* [JOB-#{id}] #{name} completed after %.4f" % runtime return repeat rescue Exception => e begin repeat e., e.backtrace rescue => e2 logger.warn "Job[#{id}] could not repeat #{e2.} #{e2.backtrace.join("\n")}" self.update_attributes(:failed_at=>Time.now,:last_error => "Could not repeat #{e2.} #{e2.backtrace.join("\n")}") end log_exception(e) return false # work failed end |
#total_runs ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/delayed/repeating_job.rb', line 13 def total_runs begin @total_runs ||= payload_object.total_runs || 0 rescue => e @total_runs ||= 0 end end |
#total_runs=(value) ⇒ Object
21 22 23 |
# File 'lib/delayed/repeating_job.rb', line 21 def total_runs=(value) @total_runs = (payload_object.total_runs = value) rescue value end |