Class: Zeridion::Flare::Worker::Configuration

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

Overview

Resolved worker configuration. One bootstrap object — there is no separate "Configuration class vs Worker class" split; Worker.new builds this from its keyword args and normalizes defaults here.

Constant Summary collapse

DEFAULT_QUEUES =
["default"].freeze
DEFAULT_CONCURRENCY =
10
DEFAULT_POLL_INTERVAL_S =
2.0
DEFAULT_TIMEOUT_S =
1800
DEFAULT_MAX_ATTEMPTS =
3
DEFAULT_SHUTDOWN_GRACE_S =
30.0
DEFAULT_POLL_READ_TIMEOUT_S =

The worker owns its own HTTP client with a poll read-timeout > 30 s so the ~30 s long-poll never trips the client's own read deadline (decision D5). 45 s leaves margin for the server's long-poll plus slack.

45.0
DEFAULT_RPC_TIMEOUT_S =

Heartbeat / ack use a short read-timeout (these are quick round-trips).

15.0
HEARTBEAT_FLOOR_MS =

Floor on the heartbeat cadence in milliseconds (10 s, per the protocol). Shrinkable for deterministic tests via FLARE_HEARTBEAT_MIN_MS (test seam D8) or the explicit heartbeat_min_ms: keyword.

10_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queues: nil, concurrency: DEFAULT_CONCURRENCY, poll_interval_s: DEFAULT_POLL_INTERVAL_S, default_timeout_s: DEFAULT_TIMEOUT_S, default_max_attempts: DEFAULT_MAX_ATTEMPTS, shutdown_grace_s: DEFAULT_SHUTDOWN_GRACE_S, poll_read_timeout_s: DEFAULT_POLL_READ_TIMEOUT_S, rpc_timeout_s: DEFAULT_RPC_TIMEOUT_S, hostname: nil, logger: nil, heartbeat_min_ms: nil) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • queues (Array<String>, nil) (defaults to: nil)

    queues to poll. nil → the union of every registered job's queue (falls back to ["default"]).

  • concurrency (Integer) (defaults to: DEFAULT_CONCURRENCY)

    max simultaneous jobs (clamped >= 1).

  • poll_interval_s (Numeric) (defaults to: DEFAULT_POLL_INTERVAL_S)

    idle delay between empty polls.

  • default_timeout_s (Integer) (defaults to: DEFAULT_TIMEOUT_S)

    timeout when a job item omits one.

  • default_max_attempts (Integer) (defaults to: DEFAULT_MAX_ATTEMPTS)
  • shutdown_grace_s (Numeric) (defaults to: DEFAULT_SHUTDOWN_GRACE_S)

    max time to await in-flight jobs on stop.

  • poll_read_timeout_s (Numeric) (defaults to: DEFAULT_POLL_READ_TIMEOUT_S)

    poll HTTP read timeout (> 30 s).

  • rpc_timeout_s (Numeric) (defaults to: DEFAULT_RPC_TIMEOUT_S)

    heartbeat/ack HTTP read timeout.

  • hostname (String, nil) (defaults to: nil)

    register hostname (default: machine name).

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

    runtime logger (nil → silent).

  • heartbeat_min_ms (Integer, nil) (defaults to: nil)

    override the 10 s heartbeat floor (test seam). Falls back to FLARE_HEARTBEAT_MIN_MS, then 10_000.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/zeridion_flare/worker/configuration.rb', line 46

def initialize(
  queues: nil,
  concurrency: DEFAULT_CONCURRENCY,
  poll_interval_s: DEFAULT_POLL_INTERVAL_S,
  default_timeout_s: DEFAULT_TIMEOUT_S,
  default_max_attempts: DEFAULT_MAX_ATTEMPTS,
  shutdown_grace_s: DEFAULT_SHUTDOWN_GRACE_S,
  poll_read_timeout_s: DEFAULT_POLL_READ_TIMEOUT_S,
  rpc_timeout_s: DEFAULT_RPC_TIMEOUT_S,
  hostname: nil,
  logger: nil,
  heartbeat_min_ms: nil
)
  @queues = normalize_queues(queues)
  @concurrency = [concurrency.to_i, 1].max
  @poll_interval_s = poll_interval_s.to_f
  @default_timeout_s = [default_timeout_s.to_i, 1].max
  @default_max_attempts = [default_max_attempts.to_i, 1].max
  @shutdown_grace_s = shutdown_grace_s.to_f
  @poll_read_timeout_s = poll_read_timeout_s.to_f
  @rpc_timeout_s = rpc_timeout_s.to_f
  @hostname = hostname
  @logger = logger
  @heartbeat_min_ms = resolve_heartbeat_min_ms(heartbeat_min_ms)
end

Instance Attribute Details

#concurrencyObject (readonly)

Returns the value of attribute concurrency.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def concurrency
  @concurrency
end

#default_max_attemptsObject (readonly)

Returns the value of attribute default_max_attempts.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def default_max_attempts
  @default_max_attempts
end

#default_timeout_sObject (readonly)

Returns the value of attribute default_timeout_s.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def default_timeout_s
  @default_timeout_s
end

#heartbeat_min_msObject (readonly)

Returns the value of attribute heartbeat_min_ms.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def heartbeat_min_ms
  @heartbeat_min_ms
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def hostname
  @hostname
end

#loggerObject (readonly)

Returns the value of attribute logger.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def logger
  @logger
end

#poll_interval_sObject (readonly)

Returns the value of attribute poll_interval_s.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def poll_interval_s
  @poll_interval_s
end

#poll_read_timeout_sObject (readonly)

Returns the value of attribute poll_read_timeout_s.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def poll_read_timeout_s
  @poll_read_timeout_s
end

#queuesObject (readonly)

Returns the value of attribute queues.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def queues
  @queues
end

#rpc_timeout_sObject (readonly)

Returns the value of attribute rpc_timeout_s.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def rpc_timeout_s
  @rpc_timeout_s
end

#shutdown_grace_sObject (readonly)

Returns the value of attribute shutdown_grace_s.



29
30
31
# File 'lib/zeridion_flare/worker/configuration.rb', line 29

def shutdown_grace_s
  @shutdown_grace_s
end

Instance Method Details

#explicit_queues?Boolean

Whether the user pinned an explicit queue list (vs deriving from jobs).

Returns:

  • (Boolean)


73
74
75
# File 'lib/zeridion_flare/worker/configuration.rb', line 73

def explicit_queues?
  !@queues.nil?
end