protected async Task CreateWorkerProcess(RemoteCodeSession session) { if (session == null) { throw new ArgumentNullException(nameof(session)); } else { await Task.Run(() => { try { //string workerExePath = Path.Combine(env.ContentRootPath, "_workerProcess", "worker", "Sigged.CodeHost.Worker.dll"); //Logger.LogLine($"Starting process at {workerExePath}"); //session.WorkerProcess = new NativeWorkerProcess(workerExePath); session.WorkerProcess = new DockerWorkerProcess(); session.WorkerProcess.Start(WEBCONTAINERALIAS, LISTENPORT, session.SessionId); } catch (IOException ioex) { Logger.LogLine(ioex.Message); throw; } catch (Exception ex) { Logger.LogLine(ex.Message); throw; } }); } }
public RemoteCodeSession CreateSession(string uniqueSessionId) { string sessionid = uniqueSessionId; var session = new RemoteCodeSession() { SessionId = sessionid }; lock (this) { session.Heartbeat(); sessions.Add(session); } return(session); }
protected async Task CreateWorkerProcess(RemoteCodeSession session) { if (session == null) { throw new ArgumentNullException(nameof(session)); } else { await Task.Run(() => { try { string workerExePath = Path.Combine(env.ContentRootPath, "_workerProcess", "worker", "Sigged.CodeHost.Worker.dll"); Logger.LogLine($"Starting process at {workerExePath}"); session.WorkerProcess = new Process(); session.WorkerProcess.EnableRaisingEvents = true; session.WorkerProcess.Exited += (object sender, EventArgs e) => { ResetSessionWorker(session, WorkerResetReason.WorkerStopped); }; session.WorkerProcess.StartInfo = new ProcessStartInfo { FileName = "dotnet", Arguments = $"{workerExePath} localhost 2000 {session.SessionId}", UseShellExecute = false }; session.WorkerProcess.Start(); } catch (IOException ioex) { Logger.LogLine(ioex.Message); throw; } catch (Exception ex) { Logger.LogLine(ex.Message); throw; } }); } }
protected void ResetSessionWorker(RemoteCodeSession session, WorkerResetReason reason) { Logger.LogLine($"Worker Reset: {session.SessionId}"); session.WorkerClient?.Close(); Logger.LogLine($"Worker Reset: closed worker socket of {session.SessionId}"); try { if (session.WorkerProcess?.HasExited == false) { session.WorkerProcess?.Kill(); Logger.LogLine($"Worker Reset: killed worker process of {session.SessionId}"); //notify client of worker destruction if (reason == WorkerResetReason.Expired && //don't notify if worker is no longer executing user code session.LastAppState != RemoteAppState.NotRunning && session.LastAppState != RemoteAppState.Ended && session.LastAppState != RemoteAppState.Crashed ) { clientService.SendExecutionState(session.SessionId, new ExecutionStateDto { SessionId = session.SessionId, State = RemoteAppState.Crashed, Exception = ExceptionDto.FromException(new TimeoutException( $"Your application takes longer than {SessionConstants.SessionIdleTimeout} seconds to execute and has been terminated.")) }); } } } finally { session.WorkerClient?.Dispose(); session.WorkerProcess?.Dispose(); session.WorkerProcess = null; session.WorkerClient = null; } }