using System; using System.Diagnostics; namespace AyaNova.Util { /// /// Used by reporting system to ensure headless browsers don't hang around in an untimely manner /// needed due to bugs in puppeteersharp where it won't close the browser on timeout properly /// also zombie process issues in linux etc, this just ensures it's safe /// This is triggered when a report is rendered /// internal static class ReportingProcessCache { internal static int ReporterProcessId { get; set; } = -1; internal static DateTime Started { get; set; } internal static void EnsureReporterAvailable(int timeOutMilliSeconds) { if (ReporterProcess() == null) return; //await it's completion in the specified timeout } internal static void FlagNewProcess(int processId) { ReporterProcessId = processId; Started = DateTime.UtcNow; } private static Process ReporterProcess() { if (ReporterProcessId == -1) return null; try { return Process.GetProcessById(ReporterProcessId); } catch (ArgumentException) { return null;//no process available / not running } } /* //Is the report generator (browser) already running? if(ReportingProcessCache.ReporterProcess()!=null){ //there is an existing process in action, let's wait for timeout seconds and kill it if it's still running before proceeding //first check to see if it's still actually running or not: var process = System.Diagnostics.Process.GetProcessById(ReportingProcessCache.ReporterProcessId); // if (ChromiumProcessID > 0 && process?.HasExited == false) // { // log.LogError($"Error during render, Chromium process (pid {ChromiumProcessID}) still active, forcing it to stop now"); // process.Kill(); // } bool keepOnWaiting=true; while(keepOnWaiting){ var v= DateTime.UtcNow-ReportingProcessCache.Started; if(v.TotalSeconds> ServerBootConfig.REPORT_RENDERING_OPERATION_TIMEOUT){ } } } */ }//eoc }//eons