public override async Task Start(string args) { await _process.Start($"{args} --InitializationPipeName {_ipcConnection.ConnectionId}"); try { await _ipcConnection.Connect().Timeout(_config.IpcConnectTimeout, $"Connecting to initialization pipe has timed out, make sure that the app {this.Identity} is connecting to the same pipe"); Trace.TraceInformation($"Yams is waiting for the app {this.Identity} to finish initializing"); string msg = await _ipcConnection.ReadMessage() .Timeout(_config.AppInitTimeout, $"Did not receive initialized message from the app {ExePath}"); if (msg != "[INITIALIZE_DONE]") { throw new InvalidOperationException($"Unexpected message '{msg}' received from app {this.Identity}"); } } catch (Exception) { await Kill(); throw; } Trace.TraceInformation($"Received initialized message from App {this.Identity}; App is ready to receive requests"); }
private void MonitorProcessHealth() { _watchProcessHealthCancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = _watchProcessHealthCancellationTokenSource.Token; _watchProcessHealthTask = Task.Run(async() => { while (!cancellationToken.IsCancellationRequested) { Trace.TraceInformation("Waiting for heart beat from app"); Task <string> readMessageTask = _ipcConnection.ReadMessage(); await WaitForHeartBeat(cancellationToken, readMessageTask); } }, cancellationToken); }
private async Task WaitForExit() { if (_exitConnection == null) { return; } while (true) { Trace.TraceInformation("Waiting for an exit message from Yams.."); string msg = await _exitConnection.ReadMessage(); if (msg == "[EXIT]") { Trace.TraceInformation("Exit request received from Yams"); ExitMessageReceived?.Invoke(this, EventArgs.Empty); break; } Trace.TraceError($"Unexpected message received from app: {msg}, Expected [EXIT]"); } }