Method: Brown::Agent.run
- Defined in:
- lib/brown/agent.rb
.run ⇒ Object
Start the agent running.
This fires off the stimuli listeners and then waits. If you want to do anything else while this runs, you'll want to fire this in a separate thread.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/brown/agent.rb', line 299 def run begin # Some memos (AMQPPublisher being the first) work best when # initialized when the agent starts up. At some point in the # future, we might implement selective initialisation, but for # now we'll take the brutally-simple approach of getting # everything. (@memos || {}).keys.each { |k| send(k, &->(_){}) } @thread_group ||= ThreadGroup.new @runner_thread = Thread.current (stimuli || {}).each do |s| @thread_group.add( Thread.new(s) do |s| begin s.run rescue Brown::StopSignal # OK then end end ) end @thread_group.list.each do |th| begin th.join rescue Brown::StopSignal # OK then end end rescue Exception => ex logger.error { "Agent #{self} caught unhandled exception: #{ex.} (#{ex.class})" } logger.info { ex.backtrace.map { |l| " #{l}" }.join("\n") } stop end end |