Class: Antigravity::Sidecar::Runner
- Defined in:
- lib/antigravity/sidecar.rb
Overview
Abstract runner for non-blocking agent sidecars. Subclass and implement #process_event.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#worker_thread ⇒ Object
readonly
Returns the value of attribute worker_thread.
Instance Method Summary collapse
- #emit(event_type, payload = {}) ⇒ Object
-
#initialize(name = "SidecarWorker") ⇒ Runner
constructor
A new instance of Runner.
- #start! ⇒ Object
- #stop! ⇒ Object
Methods inherited from Base
Methods included from Emojifiable
Constructor Details
#initialize(name = "SidecarWorker") ⇒ Runner
Returns a new instance of Runner.
15 16 17 18 19 20 |
# File 'lib/antigravity/sidecar.rb', line 15 def initialize(name = "SidecarWorker") @name = name @queue = Queue.new @running = false start! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/antigravity/sidecar.rb', line 13 def name @name end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
13 14 15 |
# File 'lib/antigravity/sidecar.rb', line 13 def queue @queue end |
#worker_thread ⇒ Object (readonly)
Returns the value of attribute worker_thread.
13 14 15 |
# File 'lib/antigravity/sidecar.rb', line 13 def worker_thread @worker_thread end |
Instance Method Details
#emit(event_type, payload = {}) ⇒ Object
37 38 39 |
# File 'lib/antigravity/sidecar.rb', line 37 def emit(event_type, payload = {}) @queue.push({ type: event_type, payload: payload, timestamp: Time.now.utc.iso8601 }) end |
#start! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/antigravity/sidecar.rb', line 22 def start! return if @running @running = true @worker_thread = Thread.new do while @running event = @queue.pop break if event == :stop process_event(event) rescue nil end end @worker_thread.priority = -1 end |
#stop! ⇒ Object
41 42 43 44 45 |
# File 'lib/antigravity/sidecar.rb', line 41 def stop! @running = false @queue.push(:stop) @worker_thread&.join(2) end |