Class: Zeridion::Flare::Worker::ProgressSlot

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

Overview

Holds the latest progress value for one in-flight job. Clamp-only, last-write-wins (decision D3): the server enforces monotonicity, so the client never adds its own "non-decreasing" guard. Values that are nil, NaN, <= 0, or otherwise out of range are dropped — #get then returns nil and the heartbeat omits the progress key entirely.

A value > 1 is clamped to 1.0 (the protocol says clamp the high end but treat <= 0 / NaN as unset). Mutex-guarded so a free-threaded Ruby (3.13+ --mjit/--yjit no-GVL builds) sees a consistent value across the handler thread (which writes) and the heartbeat thread (which reads).

Instance Method Summary collapse

Constructor Details

#initializeProgressSlot

Returns a new instance of ProgressSlot.



17
18
19
20
# File 'lib/zeridion_flare/worker/progress_slot.rb', line 17

def initialize
  @mutex = Mutex.new
  @value = nil
end

Instance Method Details

#getFloat?

Returns the latest clamped progress, or nil if never set.

Returns:

  • (Float, nil)

    the latest clamped progress, or nil if never set.



37
38
39
# File 'lib/zeridion_flare/worker/progress_slot.rb', line 37

def get
  @mutex.synchronize { @value }
end

#set(value) ⇒ Object

Record a progress value. nil / NaN / <= 0 → drop (slot unchanged).

1 → clamp to 1.0. Otherwise store as-is.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zeridion_flare/worker/progress_slot.rb', line 24

def set(value)
  return if value.nil?
  return unless value.is_a?(Numeric)

  f = value.to_f
  return if f.nan?
  return if f <= 0.0

  f = 1.0 if f > 1.0
  @mutex.synchronize { @value = f }
end