Module: Operationable::Persisters::Memory
- Extended by:
- ActiveSupport::Concern, Forwardable
- Included in:
- OperationJob
- Defined in:
- lib/operationable/persisters/memory.rb
Defined Under Namespace
Classes: Killed, NotANumber
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#at(num, total, *messages) ⇒ Object
set the status of the job for the current itteration.
-
#completed(*messages) ⇒ Object
set the status to ‘completed’ passing along any addional messages.
- #create_status_hash(job) ⇒ Object
-
#failed(*messages) ⇒ Object
set the status to ‘failed’ passing along any additional messages.
-
#kill! ⇒ Object
kill the current job, setting the status to ‘killed’ and raising
Killed. - #name ⇒ Object
-
#safe_perform(job, block) ⇒ Object
Run by the Resque::Worker when processing this job.
-
#should_kill? ⇒ Boolean
Checks against the kill list if this specific job instance should be killed on the next iteration.
-
#status ⇒ Object
get the Resque::Plugins::Status::Hash object for the current uuid.
-
#status=(new_status) ⇒ Object
Set the jobs status.
-
#tick(*messages) ⇒ Object
sets the status of the job for the current itteration.
- #working ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/operationable/persisters/memory.rb', line 15 def @options end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
15 16 17 |
# File 'lib/operationable/persisters/memory.rb', line 15 def uuid @uuid end |
Instance Method Details
#at(num, total, *messages) ⇒ Object
set the status of the job for the current itteration. num and total are passed to the status as well as any messages. This will kill the job if it has been added to the kill list with Resque::Plugins::Status::Hash.kill()
82 83 84 85 86 87 88 89 90 |
# File 'lib/operationable/persisters/memory.rb', line 82 def at(num, total, *) if total.to_f <= 0.0 raise(NotANumber, "Called at() with total=#{total} which is not a number") end tick({ 'num' => num, 'total' => total }, *) end |
#completed(*messages) ⇒ Object
set the status to ‘completed’ passing along any addional messages
111 112 113 114 115 116 |
# File 'lib/operationable/persisters/memory.rb', line 111 def completed(*) set_status({ 'status' => Operationable::Persisters::Base::STATUS_COMPLETED, 'message' => "Completed at #{Time.now}" }, *) end |
#create_status_hash(job) ⇒ Object
17 18 19 |
# File 'lib/operationable/persisters/memory.rb', line 17 def create_status_hash(job) Resque::Plugins::Status::Hash.create(self.job_id, arguments.first) end |
#failed(*messages) ⇒ Object
set the status to ‘failed’ passing along any additional messages
106 107 108 |
# File 'lib/operationable/persisters/memory.rb', line 106 def failed(*) set_status({'status' => Operationable::Persisters::Base::STATUS_FAILED}, *) end |
#kill! ⇒ Object
kill the current job, setting the status to ‘killed’ and raising Killed
119 120 121 122 123 124 125 |
# File 'lib/operationable/persisters/memory.rb', line 119 def kill! set_status({ 'status' => Operationable::Persisters::Base::STATUS_KILLED, 'message' => "Killed at #{Time.now}" }) raise Killed end |
#name ⇒ Object
68 69 70 |
# File 'lib/operationable/persisters/memory.rb', line 68 def name "#{self.class.name}(#{.inspect unless .empty?})" end |
#safe_perform(job, block) ⇒ 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/operationable/persisters/memory.rb', line 33 def safe_perform(job, block) working block.call 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) rescue Killed Resque::Plugins::Status::Hash.killed(uuid) on_killed if respond_to?(:on_killed) rescue => e failed("The task failed because of an error: #{e}") if respond_to?(:on_failure) on_failure(e) else raise e end end |
#should_kill? ⇒ Boolean
Checks against the kill list if this specific job instance should be killed on the next iteration
74 75 76 |
# File 'lib/operationable/persisters/memory.rb', line 74 def should_kill? Resque::Plugins::Status::Hash.should_kill?(uuid) end |
#status ⇒ Object
get the Resque::Plugins::Status::Hash object for the current uuid
64 65 66 |
# File 'lib/operationable/persisters/memory.rb', line 64 def status Resque::Plugins::Status::Hash.get(uuid) end |
#status=(new_status) ⇒ Object
Set the jobs status. Can take an array of strings or hashes that are merged (in order) into a final status hash.
59 60 61 |
# File 'lib/operationable/persisters/memory.rb', line 59 def status=(new_status) Resque::Plugins::Status::Hash.set(uuid, *new_status) end |
#tick(*messages) ⇒ Object
sets the status of the job for the current itteration. 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::Plugins::Status::Hash.kill()
100 101 102 103 |
# File 'lib/operationable/persisters/memory.rb', line 100 def tick(*) kill! if should_kill? set_status({'status' => Operationable::Persisters::Base::STATUS_WORKING}, *) end |
#working ⇒ Object
92 93 94 |
# File 'lib/operationable/persisters/memory.rb', line 92 def working set_status({'status' => Operationable::Persisters::Base::STATUS_WORKING}) end |