Class: Nanite::Job

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

Overview

JobWarden

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#completedObject (readonly)

Returns the value of attribute completed.



58
59
60
# File 'lib/nanite/job.rb', line 58

def completed
  @completed
end

#intermediate_handlerObject (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_stateObject (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_keysObject (readonly)

Returns the value of attribute pending_keys.



58
59
60
# File 'lib/nanite/job.rb', line 58

def pending_keys
  @pending_keys
end

#requestObject (readonly)

Returns the value of attribute request.



58
59
60
# File 'lib/nanite/job.rb', line 58

def request
  @request
end

#resultsObject (readonly)

Returns the value of attribute results.



58
59
60
# File 'lib/nanite/job.rb', line 58

def results
  @results
end

#targetsObject

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

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

Returns:

  • (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.messagekey] ||= []
    intermediate_state[msg.from][msg.messagekey] << msg.message
    @pending_keys << msg.messagekey
  end
end

#reset_pending_intermediate_state_keysObject



95
96
97
# File 'lib/nanite/job.rb', line 95

def reset_pending_intermediate_state_keys
  @pending_keys = []
end