Class: Smith::AgentProcess
- Inherits:
-
Object
- Object
- Smith::AgentProcess
show all
- Extended by:
- Forwardable
- Includes:
- Logger, Utils
- Defined in:
- lib/smith/agent_process.rb
Defined Under Namespace
Classes: AgentState
Instance Method Summary
collapse
Methods included from Utils
#agent_directories, check_and_create_directory, class_from_name, class_name_from_path, path_from_class, split_path
Methods included from Logger
included
Constructor Details
#initialize(db, attributes = {}) ⇒ AgentProcess
Returns a new instance of AgentProcess.
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/smith/agent_process.rb', line 122
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
92
93
94
95
96
97
|
# File 'lib/smith/agent_process.rb', line 92
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.
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/smith/agent_process.rb', line 104
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.
#delete ⇒ Object
99
100
101
|
# File 'lib/smith/agent_process.rb', line 99
def delete
@db.delete(@agent_state.uuid)
end
|
#exists? ⇒ Boolean
135
136
137
|
# File 'lib/smith/agent_process.rb', line 135
def exists?
agent_directories(name)
end
|
#started_at ⇒ Object
84
85
86
|
# File 'lib/smith/agent_process.rb', line 84
def started_at
Time.at(@agent_state.started_at)
end
|
#started_at=(time) ⇒ Object
88
89
90
|
# File 'lib/smith/agent_process.rb', line 88
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
|