private string GetDeathErrorMessage(IFusionProcess process) { var builder = new StringBuilder(); builder.AppendLine(ScheduleException.Dead); builder.AppendLine(process.GetErrorOutput()); return(builder.ToString()); }
private async Task TerminateAsync(IFusionProcess process, CancellationToken token) { try { await process.TerminateAsync(token); (process as IDisposable).Dispose(); } finally { processes?.Remove(process.FusionId); } }
private async Task FetchNurseStatusAsync(IFusionProcess process, CancellationToken token) { IEnumerable <PatientStatus> statusses; try { statusses = (await process.NurseStatusAsync("*", token)).Stale(); foreach (var status in statusses) { logService.Debug($"Patient: '{status.Id}' received for : '{process.FusionId}' with status '{status.Type}'."); } } catch (Exception ex) { throw new ScheduleException(ScheduleException.NurseStatusFailure, process.FusionId, ex); } var allowNoPatients = configStore.Value.Fuse.AllowFusionsWithoutPatients; if (!allowNoPatients && !statusses.Any()) { var builder = new StringBuilder(); builder.AppendLine(ScheduleException.NurseUnhealthyPatientsPrefix); builder.AppendLine(); builder.AppendLine("No patients created for this fusion."); throw new ScheduleException(builder.ToString(), process.FusionId); } var unhealthyStatusses = statusses .Where(_ => _.Type == PatientStatusType.Red) .ToArray(); if (unhealthyStatusses.Any()) { var builder = new StringBuilder(); builder.AppendLine(ScheduleException.NurseUnhealthyPatientsPrefix); foreach (var status in unhealthyStatusses) { builder.AppendLine(); builder.AppendLine($"Id: {status.Id}"); builder.AppendLine($"Status: {status.Type.ToString()}"); builder.AppendLine($"Reason: {status.Reason}"); } throw new ScheduleException(builder.ToString(), process.FusionId); } }
private async Task StartupAsync(IFusionProcess process, CancellationToken token) { await process.StartupAsync(token); foreach (var interceptor in interceptors) { token.ThrowIfCancellationRequested(); interceptor.OnStartupCalled(process); logService.Debug($"Interceptor: '{interceptor.GetType().Name}' called for fusion: '{process.FusionId}'."); } process.OnInterceptorsInformed(); await FetchNurseStatusAsync(process, token); }
private async Task <FusionStatus> GetFusionStatusAsync( IFusionProcess process, string patientPattern, CancellationToken token) { try { var patients = await process.NurseStatusAsync(patientPattern, token); return(new FusionStatus(process.FusionId, patients)); } catch (Exception ex) { return(new FusionStatus(process.FusionId, new[] { new PatientStatus(unknownPatientId, PatientStatusType.Red, ex.ToString()) })); } }
private bool TryGetActiveProcess(string fusionId, out IFusionProcess process) { process = default(IFusionProcess); return(processes?.TryGetValue(fusionId, out process) == true); }