Class: Nanite::JobWarden

Inherits:
Object show all
Defined in:
lib/nanite/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#jobsObject (readonly)

Returns the value of attribute jobs.



3
4
5
# File 'lib/nanite/job.rb', line 3

def jobs
  @jobs
end

#logObject (readonly)

Returns the value of attribute log.



3
4
5
# File 'lib/nanite/job.rb', line 3

def log
  @log
end

#serializerObject (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