Class: Zeridion::Flare::Worker::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/zeridion_flare/worker/runner.rb

Overview

The poll loop. Runs register-once → poll → dispatch → ack, and bounds the poll capacity to true free slots clamped 1–50. Owns no threads of its own beyond the per-job heartbeat pumps it starts; the bounded job threads live in the Pool. Mirrors the reference SDK's poll-loop service.

Constant Summary collapse

CAPACITY_MIN =
1
CAPACITY_MAX =
50

Instance Method Summary collapse

Constructor Details

#initialize(worker_id:, config:, registry:, executor:, pool:, poll_client:, heartbeat_client:, ack_client:, register_client:, stop_token:, logger: nil) ⇒ Runner

Returns a new instance of Runner.

Parameters:

  • worker_id (String)
  • config (Configuration)
  • registry (Registry)
  • executor (Executor)
  • pool (Pool)
  • poll_client (Object)

    strict client; worker owns it (long read-timeout, no poll-timeout retry)

  • heartbeat_client (Object)

    strict client for heartbeats

  • ack_client (Object)

    strict client for acks (<= 1 retry)

  • register_client (Object)

    strict client for register

  • stop_token (CancellationToken)

    flips on host shutdown / #stop

  • logger (Logger, nil) (defaults to: nil)


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

def initialize(worker_id:, config:, registry:, executor:, pool:,
               poll_client:, heartbeat_client:, ack_client:, register_client:,
               stop_token:, logger: nil)
  @worker_id = worker_id
  @config = config
  @registry = registry
  @executor = executor
  @pool = pool
  @poll_client = poll_client
  @heartbeat_client = heartbeat_client
  @ack_client = ack_client
  @register_client = register_client
  @stop = stop_token
  @logger = logger
end

Instance Method Details

#runObject

Run the loop on the CURRENT thread until the stop token trips. The caller (Worker) decides whether that is the main thread or a spawned poll thread.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/zeridion_flare/worker/runner.rb', line 44

def run
  if @registry.empty?
    @logger&.warn("worker_starting no job types discovered — worker will not poll")
    return
  end

  queues = poll_queues
  job_types = @registry.job_types

  @logger&.info(
    "worker_starting worker_id=#{@worker_id} job_type_count=#{job_types.length} " \
    "queues=#{queues.join(',')}",
  )

  register(queues, job_types)
  poll_loop(queues, job_types)
end