Class: Antigravity::Sidecar::Runner

Inherits:
Base
  • Object
show all
Defined in:
lib/antigravity/sidecar.rb

Overview

Abstract runner for non-blocking agent sidecars. Subclass and implement #process_event.

Direct Known Subclasses

AuditLogger, VulnerabilityScanner

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited

Methods included from Emojifiable

#emoji, included

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

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/antigravity/sidecar.rb', line 13

def name
  @name
end

#queueObject (readonly)

Returns the value of attribute queue.



13
14
15
# File 'lib/antigravity/sidecar.rb', line 13

def queue
  @queue
end

#worker_threadObject (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