Class: Textus::Maintenance::Drain

Inherits:
Object
  • Object
show all
Extended by:
Contract::DSL
Defined in:
lib/textus/maintenance/drain.rb

Overview

Converge-and-exit: seed the full convergence set for the scope, run the worker until the queue is empty, return a health summary. Exits not-ok if any job dead-lettered. This is the converge entry point and what CI runs. Single-pass (serial) on purpose: each produce job self-locks via Produce::Engine.converge, so running them in turn keeps the build lock uncontended; a concurrent pool would make all-but-one produce job hit BuildInProgress and skip.

Instance Method Summary collapse

Methods included from Contract::DSL

arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view

Constructor Details

#initialize(container:, call:) ⇒ Drain

Returns a new instance of Drain.



20
21
22
23
# File 'lib/textus/maintenance/drain.rb', line 20

def initialize(container:, call:)
  @container = container
  @call = call
end

Instance Method Details

#call(prefix: nil, zone: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/textus/maintenance/drain.rb', line 25

def call(prefix: nil, zone: nil)
  queue = Textus::Ports::Queue.new(root: @container.root)
  Textus::Jobs::Seeder.new(container: @container, queue: queue, call: @call).seed(prefix: prefix, zone: zone)

  summary = Worker.for(container: @container, queue: queue).drain
  health = Read::Doctor.new(container: @container, call: @call).call

  {
    "protocol" => Textus::PROTOCOL,
    "ok" => summary.failed.zero?,
    "completed" => summary.completed,
    "failed" => summary.failed,
    "health" => health,
  }
end