using ZB.MOM.WW.MxGateway.Contracts.Proto; namespace ZB.MOM.WW.MxGateway.Server.Workers; /// Manages communication with a single worker process via a named pipe. public interface IWorkerClient : IAsyncDisposable { /// Unique session identifier for this worker. string SessionId { get; } /// Process ID of the worker, or null before handshake completes. int? ProcessId { get; } /// Current state of the worker connection. WorkerClientState State { get; } /// UTC timestamp of the most recent heartbeat from the worker. DateTimeOffset LastHeartbeatAt { get; } /// Initiates the handshake and enters ready state. /// Token to cancel the asynchronous operation. Task StartAsync(CancellationToken cancellationToken); /// Sends a command to the worker and waits for a reply. /// Worker command to invoke. /// Timeout for waiting for the reply. /// Token to cancel the asynchronous operation. Task InvokeAsync( WorkerCommand command, TimeSpan timeout, CancellationToken cancellationToken); /// Reads events from the worker as they arrive. /// Token to cancel the asynchronous operation. IAsyncEnumerable ReadEventsAsync(CancellationToken cancellationToken); /// Gracefully shuts down the worker by closing the connection. /// Timeout for shutdown. /// Token to cancel the asynchronous operation. Task ShutdownAsync(TimeSpan timeout, CancellationToken cancellationToken); /// Terminates the worker process immediately with a diagnostic reason. /// Reason for terminating the worker. void Kill(string reason); }