Class: MotherBrain::Job Private
- Inherits:
-
Object
- Object
- MotherBrain::Job
- Extended by:
- Forwardable
- Includes:
- Celluloid, MB::Job::States, MB::Logging, MB::Mixin::Services
- Defined in:
- lib/mb/job.rb,
lib/mb/job/states.rb,
lib/mb/job/state_machine.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A Celluloid actor representing an active job. Jobs are handled by the JobManager and should not be returned to a consumer or user from the Public API.
Jobs start in the ‘pending’ state and can only be in any one state at a given time. A Job is completed when in the ‘success’ or ‘failure’ state.
The progress of a Job is recorded by the JobManager as a JobRecord. API consumers should reference the status of a running Job by it’s JobRecord.
Returning a JobTicket from the Public API will give a consumer or user an easy way to check the status of a job by polling a Job’s JobRecord.
Defined Under Namespace
Modules: States Classes: StateMachine
Instance Attribute Summary collapse
- #id ⇒ Object readonly private
- #result ⇒ Object readonly private
-
#time_end ⇒ Time
private
Set when the state of the Job changes from ‘running’ to ‘sucess’ or ‘failure’.
-
#time_start ⇒ Time
private
Set when the state of the Job changes from ‘pending’ to ‘running’.
- #type ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(type) ⇒ Job
constructor
private
A new instance of Job.
- #report_boolean(boolean, result = nil, options = {}) ⇒ Job private
- #report_failure(result = nil, options = {}) ⇒ Job private
- #report_pending(result = nil, options = {}) ⇒ Job private
- #report_running(result = nil, options = {}) ⇒ Job private
- #report_success(result = nil, options = {}) ⇒ Job private
- #save ⇒ self private
- #status ⇒ Object private
- #status=(string) ⇒ Object (also: #set_status) private
- #status_buffer ⇒ Object private
- #ticket ⇒ JobTicket private
- #to_s ⇒ Object (also: #inspect) private
- #transition(state, result = nil, options = {}) ⇒ Job private
Constructor Details
#initialize(type) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Job.
62 63 64 65 66 67 68 |
# File 'lib/mb/job.rb', line 62 def initialize(type) @machine = StateMachine.new @type = type.to_s @id = job_manager.uuid @result = nil job_manager.add(Actor.current) end |
Instance Attribute Details
#id ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/mb/job.rb', line 39 def id @id end |
#result ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/mb/job.rb', line 41 def result @result end |
#time_end ⇒ Time
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
do not modify outside of the state machine
Set when the state of the Job changes from ‘running’ to ‘sucess’ or ‘failure’
55 56 57 |
# File 'lib/mb/job.rb', line 55 def time_end @time_end end |
#time_start ⇒ Time
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
do not modify outside of the state machine
Set when the state of the Job changes from ‘pending’ to ‘running’
48 49 50 |
# File 'lib/mb/job.rb', line 48 def time_start @time_start end |
#type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/mb/job.rb', line 40 def type @type end |
Instance Method Details
#report_boolean(boolean, result = nil, options = {}) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
122 123 124 125 126 127 128 |
# File 'lib/mb/job.rb', line 122 def report_boolean(boolean, result = nil, = {}) if boolean report_success(result, ) else report_failure(result, ) end end |
#report_failure(result = nil, options = {}) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 79 |
# File 'lib/mb/job.rb', line 76 def report_failure(result = nil, = {}) log.fatal { "Job (#{id}) failure: #{result}" } transition(:failure, result, ) end |
#report_pending(result = nil, options = {}) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 |
# File 'lib/mb/job.rb', line 87 def report_pending(result = nil, = {}) log.info { "Job (#{id}) pending: #{result}" } transition(:pending, result, ) end |
#report_running(result = nil, options = {}) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 101 |
# File 'lib/mb/job.rb', line 98 def report_running(result = nil, = {}) log.info { "Job (#{id}) running: #{result}" } transition(:running, result, ) end |
#report_success(result = nil, options = {}) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 112 |
# File 'lib/mb/job.rb', line 109 def report_success(result = nil, = {}) log.info { "Job (#{id}) success: #{result}" } transition(:success, result, ) end |
#save ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
131 132 133 |
# File 'lib/mb/job.rb', line 131 def save job_manager.update(Actor.current) end |
#status ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
135 136 137 |
# File 'lib/mb/job.rb', line 135 def status @status || state.to_s.capitalize end |
#status=(string) ⇒ Object Also known as: set_status
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
139 140 141 142 143 144 |
# File 'lib/mb/job.rb', line 139 def status=(string) log.info { "Job (#{id}) status: #{string}" } @status = string status_buffer << string save end |
#status_buffer ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
147 148 149 |
# File 'lib/mb/job.rb', line 147 def status_buffer @status_buffer ||= [] end |
#ticket ⇒ JobTicket
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 |
# File 'lib/mb/job.rb', line 152 def ticket @ticket ||= JobTicket.new(id) end |
#to_s ⇒ Object Also known as: inspect
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
170 171 172 |
# File 'lib/mb/job.rb', line 170 def to_s "#<Job @type=#{type.inspect} @machine.state=#{state.inspect}>" end |
#transition(state, result = nil, options = {}) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
164 165 166 167 168 |
# File 'lib/mb/job.rb', line 164 def transition(state, result = nil, = {}) @result = result.respond_to?(:cause) ? result.cause : result machine.transition(state, ) Actor.current end |