Sha256: 71dac0dbff45da5e464ccea8be406b5361c64b1389eb924351ed9c89d8b297a6
Contents?: true
Size: 1.95 KB
Versions: 9
Compression:
Stored size: 1.95 KB
Contents
module Resque class JobWithStatus # Adds a job of type <tt>klass<tt> to the queue with <tt>options<tt>. # Returns the UUID of the job # override to pass actual parameters instead of a single hash, to make backward compatible with existing resque jobs. def self.enqueue(klass, options = {}) uuid = Resque::Status.create :name => "#{self.name}: #{options.inspect}" Resque.enqueue(klass, uuid, options) uuid end # sets the status of the job for the current iteration. You should use # the <tt>at</tt> method if you have actual numbers to track the iteration count. # This will kill the job if it has been added to the kill list with # <tt>Resque::Status.kill()</tt> def tick(*messages) kill! if should_kill? || status.killed? set_status({'status' => 'working'}, *messages) end # Run by the Resque::Worker when processing this job. It wraps the <tt>perform</tt> # method ensuring that the final status of the job is set regardless of error. # If an error occurs within the job's work, it will set the status as failed and # re-raise the error. def safe_perform! unless should_kill? || (status && status.killed?) set_status({'status' => 'working'}) perform kill! if should_kill? completed unless status && status.completed? on_success if respond_to?(:on_success) end rescue Killed logger.info "Job #{self} Killed at #{Time.now}" Resque::Status.killed(uuid) on_killed if respond_to?(:on_killed) rescue => e logger.error e failed("The task failed because of an error: #{e}") if respond_to?(:on_failure) on_failure(e) else raise e end end def name "#{self.class.name}: #{options.inspect}" end def incr_counter(counter) Resque::Status.incr_counter(counter, uuid) end def counter(counter) Resque::Status.counter(counter, uuid) end end end
Version data entries
9 entries across 9 versions & 1 rubygems