namespace ZB.MOM.WW.MxGateway.Server.Configuration;
public sealed class WorkerOptions
{
/// The path to the worker executable.
public string ExecutablePath { get; init; } =
@"src\ZB.MOM.WW.MxGateway.Worker\bin\x86\Release\ZB.MOM.WW.MxGateway.Worker.exe";
/// The working directory for the worker process, or null to inherit.
public string? WorkingDirectory { get; init; }
/// The required processor architecture for the worker.
public WorkerArchitecture RequiredArchitecture { get; init; } = WorkerArchitecture.X86;
/// The maximum time in seconds for the worker to start.
public int StartupTimeoutSeconds { get; init; } = 30;
/// The number of retry attempts for the startup probe.
public int StartupProbeRetryAttempts { get; init; } = 3;
/// The delay in milliseconds between startup probe retries.
public int StartupProbeRetryDelayMilliseconds { get; init; } = 250;
/// The timeout in milliseconds for connecting to the worker pipe.
public int PipeConnectAttemptTimeoutMilliseconds { get; init; } = 2000;
///
/// Bounded wait, in milliseconds, the worker holds a WriteSecured/WriteSecured2
/// reply for the matching MXAccess OnWriteComplete callback so the reply's
/// statuses carry the real commit outcome. 0 disables the wait. Deployments
/// raising this above consumer write-timeout budgets (e.g. OtOpcUa's 2 s Tier A
/// write resilience timeout) must raise those in step.
///
public int WriteCompletionWaitMilliseconds { get; init; } = 1500;
///
/// Capacity of the worker's outbound MXAccess event queue, in events.
/// Default 10,000; must be between 1,000 and 1,000,000. This is
/// headroom, not a throttle: the queue has no drop policy, so a burst
/// that fills it faults the session with a QueueOverflow worker
/// fault. Raise it for sessions whose subscription set can outrun the
/// drain loop (large advise sets, slow event consumers). Conveyed to
/// the worker through the MXGATEWAY_EVENT_QUEUE_CAPACITY
/// environment variable.
///
public int EventQueueCapacity { get; init; } = 10000;
/// The maximum time in seconds for graceful shutdown.
public int ShutdownTimeoutSeconds { get; init; } = 10;
/// The interval in seconds for worker heartbeats.
public int HeartbeatIntervalSeconds { get; init; } = 5;
/// The grace period in seconds after a heartbeat before considering the worker unresponsive.
public int HeartbeatGraceSeconds { get; init; } = 15;
///
/// The maximum worker-frame (pipe) message size in bytes. Must stay at least
/// above
/// so a maximally-sized accepted gRPC payload
/// still fits one worker frame; the gateway conveys this value to the worker in the
/// handshake (GatewayHello.max_frame_bytes). Default is the 16 MB public gRPC cap
/// plus that reserve.
///
public int MaxMessageBytes { get; init; } =
(16 * 1024 * 1024) + Workers.WorkerFrameProtocolOptions.EnvelopeOverheadReserveBytes;
}