Class: Nanite::JobWarden
Instance Attribute Summary collapse
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
-
#initialize(serializer, log) ⇒ JobWarden
constructor
A new instance of JobWarden.
- #new_job(request, targets, blk = nil) ⇒ Object
- #process(msg) ⇒ Object
Constructor Details
#initialize(serializer, log) ⇒ JobWarden
Returns a new instance of JobWarden.
5 6 7 8 9 |
# File 'lib/nanite/job.rb', line 5 def initialize(serializer, log) @serializer = serializer @log = log @jobs = {} end |
Instance Attribute Details
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
3 4 5 |
# File 'lib/nanite/job.rb', line 3 def jobs @jobs end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
3 4 5 |
# File 'lib/nanite/job.rb', line 3 def log @log end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
3 4 5 |
# File 'lib/nanite/job.rb', line 3 def serializer @serializer end |
Instance Method Details
#new_job(request, targets, blk = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/nanite/job.rb', line 11 def new_job(request, targets, blk = nil) job = Job.new(request, targets, blk) jobs[job.token] = job job end |
#process(msg) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nanite/job.rb', line 17 def process(msg) msg = serializer.load(msg) log.debug("processing message: #{msg.inspect}") if job = jobs[msg.token] job.process(msg) if job.completed? jobs.delete(job.token) job.completed.call(job.results) if job.completed end end end |