Class: Smith::AgentProcess
- Inherits:
-
Object
- Object
- Smith::AgentProcess
- Extended by:
- Forwardable
- Includes:
- Logger
- Defined in:
- lib/smith/agent_process.rb
Defined Under Namespace
Classes: AgentState
Instance Method Summary collapse
- #add_callback(state, &blk) ⇒ Object
-
#alive? ⇒ Boolean
Check to see if the agent is alive.
-
#control_queue_def ⇒ Object
Return the agent control queue.
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(db, attributes = {}) ⇒ AgentProcess
constructor
A new instance of AgentProcess.
- #started_at ⇒ Object
- #started_at=(time) ⇒ Object
- #to_s ⇒ Object
Methods included from Logger
Constructor Details
#initialize(db, attributes = {}) ⇒ AgentProcess
Returns a new instance of AgentProcess.
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/smith/agent_process.rb', line 120 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 |
Instance Method Details
#add_callback(state, &blk) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/smith/agent_process.rb', line 90 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? ⇒ Boolean
Check to see if the agent is alive.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/smith/agent_process.rb', line 102 def alive? if self.pid begin Process.kill(0, self.pid) true rescue Exception false end else false end end |
#control_queue_def ⇒ Object
Return the agent control queue.
116 117 118 |
# File 'lib/smith/agent_process.rb', line 116 def control_queue_def QueueDefinitions::Agent_control.call(uuid) end |
#delete ⇒ Object
97 98 99 |
# File 'lib/smith/agent_process.rb', line 97 def delete @db.delete(@agent_state.uuid) end |
#exists? ⇒ Boolean
133 134 135 136 137 |
# File 'lib/smith/agent_process.rb', line 133 def exists? Smith.agent_paths.detect do |path| Pathname.new(path).join("#{name.snake_case}.rb").exist? end end |
#started_at ⇒ Object
82 83 84 |
# File 'lib/smith/agent_process.rb', line 82 def started_at Time.at(@agent_state.started_at) end |
#started_at=(time) ⇒ Object
86 87 88 |
# File 'lib/smith/agent_process.rb', line 86 def started_at=(time) @agent_state.started_at = time.to_i end |
#to_s ⇒ Object
139 140 141 142 143 |
# File 'lib/smith/agent_process.rb', line 139 def to_s @agent_state.to_hash.tap do |h| h[:state] = h.delete(:_state) end end |