Module: Resque::Plugins::Status
- Defined in:
- lib/resque_manager/overrides/resque_status/hash.rb,
lib/resque_manager/overrides/resque_status/status.rb
Defined Under Namespace
Modules: ClassOverridesAndExtensions Classes: Hash
Class Method Summary collapse
-
.included(base) ⇒ Object
OVERRIDE so we can add OverridesAndExtensionsClassMethods.
Instance Method Summary collapse
- #counter(counter) ⇒ Object
- #incr_counter(counter) ⇒ Object
-
#initialize(uuid, worker = nil, options = {}) ⇒ Object
Create a new instance with
uuidandoptionsOVERRIDE to add the worker attr. -
#overview_message=(message) ⇒ Object
sets a message for the job on the overview page it can be set repeatedly durring the job’s processing to indicate the status of the job.
-
#pause! ⇒ Object
Pause the current job, setting the status to ‘paused’.
-
#safe_perform! ⇒ Object
Run by the Resque::Worker when processing this job.
-
#tick(*messages) ⇒ Object
sets the status of the job for the current iteration.
Class Method Details
.included(base) ⇒ Object
OVERRIDE so we can add OverridesAndExtensionsClassMethods
7 8 9 10 11 12 13 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 7 def self.included(base) attr_reader :worker # can't call super, so add ClassMethods here that resque-status was doing base.extend(ClassMethods) #add the methods in the resque-status gem base.extend(ClassOverridesAndExtensions) end |
Instance Method Details
#counter(counter) ⇒ Object
155 156 157 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 155 def counter(counter) self.class.counter(counter, uuid) end |
#incr_counter(counter) ⇒ Object
151 152 153 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 151 def incr_counter(counter) self.class.incr_counter(counter, uuid) end |
#initialize(uuid, worker = nil, options = {}) ⇒ Object
Create a new instance with uuid and options OVERRIDE to add the worker attr
104 105 106 107 108 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 104 def initialize(uuid, worker = nil, = {}) @uuid = uuid = @worker = worker end |
#overview_message=(message) ⇒ Object
sets a message for the job on the overview page it can be set repeatedly durring the job’s processing to indicate the status of the job.
146 147 148 149 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 146 def () # there is no worker when run inline self.worker. = if self.worker end |
#pause! ⇒ Object
Pause the current job, setting the status to ‘paused’
95 96 97 98 99 100 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 95 def pause! set_status({ 'status' => 'paused', 'message' => "#{worker} paused at #{Time.now}" }) end |
#safe_perform! ⇒ Object
Run by the Resque::Worker when processing this job. It wraps the perform 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. OVERRIDE to kill it. The parent job may have been killed, so all child jobs should die as well.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 115 def safe_perform! k = should_kill? kill! if k unless k || (status && status.killed?) set_status({'status' => 'working'}) perform if status && status.failed? on_failure(status.) if respond_to?(:on_failure) return elsif status && !status.completed? completed end on_success if respond_to?(:on_success) end rescue Killed Rails.logger.info "Job #{self} Killed at #{Time.now}" Resque::Plugins::Status::Hash.killed(uuid) on_killed if respond_to?(:on_killed) rescue Exception => e Rails.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 |
#tick(*messages) ⇒ Object
sets the status of the job for the current iteration. You should use the at 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 Resque::Status.kill()
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/resque_manager/overrides/resque_status/status.rb', line 78 def tick(*) kill! if should_kill? || status.killed? set_status({'status' => 'working'}, *) # check to see if the worker doing the job has been paused, pause the job if so if self.worker && self.worker.paused? loop do # Set the status to paused. # May need to do this repeatedly because there could be workers in a chained job still doing work. pause! unless status.paused? break unless self.worker.paused? sleep 60 end set_status({'status' => 'working'}, *) unless status && (status.completed? || status.paused? || status.killed?) end end |