Class: Nanite::Job
Overview
JobWarden
Instance Attribute Summary collapse
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#intermediate_handler ⇒ Object
readonly
Returns the value of attribute intermediate_handler.
-
#intermediate_state ⇒ Object
readonly
Returns the value of attribute intermediate_state.
-
#pending_keys ⇒ Object
readonly
Returns the value of attribute pending_keys.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#targets ⇒ Object
This can be updated when a request gets picked up from the offline queue.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #completed? ⇒ Boolean
-
#initialize(request, targets, inthandler = nil, blk = nil) ⇒ Job
constructor
A new instance of Job.
- #intermediate_handler_for_key(key) ⇒ Object
- #process(msg) ⇒ Object
- #reset_pending_intermediate_state_keys ⇒ Object
Constructor Details
#initialize(request, targets, inthandler = nil, blk = nil) ⇒ Job
Returns a new instance of Job.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/nanite/job.rb', line 61 def initialize(request, targets, inthandler = nil, blk = nil) @request = request @targets = targets @token = @request.token @results = {} @intermediate_handler = inthandler @pending_keys = [] @completed = blk @intermediate_state = {} end |
Instance Attribute Details
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def completed @completed end |
#intermediate_handler ⇒ Object (readonly)
Returns the value of attribute intermediate_handler.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def intermediate_handler @intermediate_handler end |
#intermediate_state ⇒ Object (readonly)
Returns the value of attribute intermediate_state.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def intermediate_state @intermediate_state end |
#pending_keys ⇒ Object (readonly)
Returns the value of attribute pending_keys.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def pending_keys @pending_keys end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def request @request end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def results @results end |
#targets ⇒ Object
This can be updated when a request gets picked up from the offline queue
59 60 61 |
# File 'lib/nanite/job.rb', line 59 def targets @targets end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
58 59 60 |
# File 'lib/nanite/job.rb', line 58 def token @token end |
Instance Method Details
#completed? ⇒ Boolean
99 100 101 |
# File 'lib/nanite/job.rb', line 99 def completed? targets.empty? end |
#intermediate_handler_for_key(key) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/nanite/job.rb', line 85 def intermediate_handler_for_key(key) return nil unless @intermediate_handler case @intermediate_handler when Proc @intermediate_handler when Hash @intermediate_handler[key] || @intermediate_handler['*'] end end |
#process(msg) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nanite/job.rb', line 72 def process(msg) case msg when Result results[msg.from] = msg.results targets.delete(msg.from) when IntermediateMessage intermediate_state[msg.from] ||= {} intermediate_state[msg.from][msg.] ||= [] intermediate_state[msg.from][msg.] << msg. @pending_keys << msg. end end |
#reset_pending_intermediate_state_keys ⇒ Object
95 96 97 |
# File 'lib/nanite/job.rb', line 95 def reset_pending_intermediate_state_keys @pending_keys = [] end |