Class: Textus::Surfaces::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/surfaces/watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(container:) ⇒ Watcher

Returns a new instance of Watcher.



8
9
10
11
# File 'lib/textus/surfaces/watcher.rb', line 8

def initialize(container:)
  @container = container
  @queue = Textus::Ports::Queue.new(root: container.root)
end

Instance Method Details

#run(poll: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/textus/surfaces/watcher.rb', line 23

def run(poll: nil)
  interval = poll || @container.manifest.data.worker_config[:poll]
  lock = Textus::Ports::WatcherLock.new(@container.root)
  lock.acquire
  begin
    loop do
      tick
      sleep(interval)
    end
  ensure
    lock.release
  end
end

#tickObject



13
14
15
16
17
18
19
20
21
# File 'lib/textus/surfaces/watcher.rb', line 13

def tick
  Textus::Background::Planner::Plan.seed(
    container: @container,
    queue: @queue,
    role: Textus::Role::AUTOMATION,
  )
  @queue.reclaim(now: Textus::Ports::Clock.new.now)
  Textus::Background::Worker.for(container: @container, queue: @queue).drain
end