feat(worker): implement Ping/GetSessionState/GetWorkerInfo/DrainEvents/ShutdownWorker control commands
Answer the five worker control/lifecycle commands at the WorkerPipeSession message-loop layer instead of the STA-bound MxAccessCommandExecutor. These replies are built from process-level state (worker pid, assembly version, worker lifecycle, the runtime session's event queue) the executor cannot see, and ShutdownWorker must emit its OK reply before the graceful shutdown joins the STA thread - dispatching it onto the STA would deadlock. - Ping: OK reply, echoes message into diagnostic_message. - GetSessionState: maps WorkerState to proto SessionState. - GetWorkerInfo: pid, worker version, MXAccess ProgID/CLSID. - DrainEvents: drains the runtime event queue into DrainEventsReply. - ShutdownWorker: OK reply, then graceful shutdown, then stops the loop. Tests added in WorkerPipeSessionTests; FakeRuntimeSession gains a batch-size drain suppressor so DrainEvents does not race the background drain loop.
This commit is contained in:
@@ -122,11 +122,26 @@ internal sealed class FakeRuntimeSession : IWorkerRuntimeSession
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When set, <see cref="DrainEvents"/> returns no events for the
|
||||
/// WorkerPipeSession background drain loop's fixed batch size, so an
|
||||
/// explicit DrainEvents control command (which drains all via
|
||||
/// <c>maxEvents == 0</c>) can claim the queued events deterministically
|
||||
/// without racing the 25 ms background loop. Mirrors
|
||||
/// <c>WorkerPipeSession.EventDrainBatchSize</c>.
|
||||
/// </summary>
|
||||
public uint? SuppressDrainForBatchSize { get; set; }
|
||||
|
||||
/// <summary>Drains queued events up to the specified limit.</summary>
|
||||
/// <param name="maxEvents">Maximum events to drain; 0 drains all.</param>
|
||||
/// <returns>The drained events.</returns>
|
||||
public IReadOnlyList<WorkerEvent> DrainEvents(uint maxEvents)
|
||||
{
|
||||
if (SuppressDrainForBatchSize is uint suppressed && maxEvents == suppressed)
|
||||
{
|
||||
return Array.Empty<WorkerEvent>();
|
||||
}
|
||||
|
||||
lock (gate)
|
||||
{
|
||||
int drainCount = maxEvents == 0
|
||||
|
||||
Reference in New Issue
Block a user