namespace ZB.MOM.WW.MxGateway.Server.Workers;
/// Configurable options for worker client behavior.
public sealed class WorkerClientOptions
{
/// Default maximum age of a heartbeat before the client enters faulted state.
public static readonly TimeSpan DefaultHeartbeatGrace = TimeSpan.FromSeconds(15);
/// Default interval for checking heartbeat staleness.
public static readonly TimeSpan DefaultHeartbeatCheckInterval = TimeSpan.FromSeconds(1);
/// Default timeout when the event queue is full.
public static readonly TimeSpan DefaultEventChannelFullModeTimeout = TimeSpan.FromSeconds(5);
///
/// Default ceiling on the in-flight-command heartbeat skip. Mirrors
///
/// on the worker side (Worker-023). When a command has been in flight
/// longer than this, the gateway-side heartbeat watchdog fires
/// regardless of pending commands — a truly stuck COM call shouldn't
/// hide the worker forever.
///
public static readonly TimeSpan DefaultHeartbeatStuckCeiling = TimeSpan.FromSeconds(75);
/// Initializes options with default values.
public WorkerClientOptions()
{
HeartbeatGrace = DefaultHeartbeatGrace;
HeartbeatCheckInterval = DefaultHeartbeatCheckInterval;
EventChannelCapacity = 1_024;
EventChannelFullModeTimeout = DefaultEventChannelFullModeTimeout;
MaxPendingCommands = 128;
HeartbeatStuckCeiling = DefaultHeartbeatStuckCeiling;
}
/// Maximum allowed age of the last heartbeat before faulting the client.
public TimeSpan HeartbeatGrace { get; init; }
/// Interval at which to check for heartbeat expiration.
public TimeSpan HeartbeatCheckInterval { get; init; }
/// Maximum number of events buffered before backpressure is applied.
public int EventChannelCapacity { get; init; }
///
/// Time to wait for the gateway-side event channel to drain before
/// faulting the worker. Honored by EnqueueWorkerEventAsync via
/// WriteAsync; with the channel configured for
/// BoundedChannelFullMode.Wait, a transient backlog only faults
/// after the configured timeout has elapsed (Server-032). Pre-Server-032
/// the field was declared but unused — overflow faulted immediately.
///
public TimeSpan EventChannelFullModeTimeout { get; init; }
/// Maximum number of concurrent pending commands.
public int MaxPendingCommands { get; init; }
///
/// Server-031: ceiling on the in-flight-command heartbeat-skip. When
/// a command has been pending on the gateway↔worker pipe for longer
/// than this, the gateway-side HeartbeatLoopAsync fires the
/// HeartbeatExpired fault even if commands are still pending;
/// a truly stuck COM call shouldn't keep the watchdog suppressed
/// indefinitely. Mirrors Worker-023's HeartbeatStuckCeiling on
/// the worker side.
///
public TimeSpan HeartbeatStuckCeiling { get; init; }
}