class Smith::AgentProcess

Public Class Methods

new(db, attributes={}) click to toggle source
Calls superclass method
# File lib/smith/agent_process.rb, line 121
def initialize(db, attributes={})
  @db = db
  if attributes.is_a?(String)
    @agent_state = AgentState.new.parse_from_string(attributes)
  else
    raise ArgumentError, "missing uuid option" if attributes[:uuid].nil?
    attr = attributes.merge(:_state => 'null')
    @agent_state = AgentState.new(attr)
  end

  super()
end

Public Instance Methods

add_callback(state, &blk) click to toggle source
# File lib/smith/agent_process.rb, line 91
def add_callback(state, &blk)
  AgentProcess.state_machine do
    puts "changing callback: :on => #{state}, :do => #{blk}"
    after_transition :on => state, :do => blk
  end
end
alive?() click to toggle source

Check to see if the agent is alive.

# File lib/smith/agent_process.rb, line 103
def alive?
  if self.pid
    begin
      Process.kill(0, self.pid)
      true
    rescue Exception
      false
    end
  else
    false
  end
end
control_queue_def() click to toggle source

Return the agent control queue.

# File lib/smith/agent_process.rb, line 117
def control_queue_def
  QueueDefinitions::Agent_control.call(uuid)
end
delete() click to toggle source
# File lib/smith/agent_process.rb, line 98
def delete
  @db.delete(@agent_state.uuid)
end
exists?() click to toggle source
# File lib/smith/agent_process.rb, line 134
def exists?
  agent_directories(name)
end
started_at() click to toggle source
# File lib/smith/agent_process.rb, line 83
def started_at
  Time.at(@agent_state.started_at)
end
started_at=(time) click to toggle source
# File lib/smith/agent_process.rb, line 87
def started_at=(time)
  @agent_state.started_at = time.to_i
end
to_s() click to toggle source
# File lib/smith/agent_process.rb, line 138
def to_s
  @agent_state.to_hash.tap do |h|
    h[:state] = h.delete(:_state)
  end
end

Private Instance Methods

_state() click to toggle source
# File lib/smith/agent_process.rb, line 146
def _state
  @agent_state._state || "null"
end
save() click to toggle source
# File lib/smith/agent_process.rb, line 150
def save
  @agent_state._state = state
  # TODO This *must* change to uuid when I've worked out how to manage them.
  @db[uuid] = @agent_state.to_s
end