/// <summary> /// Handle GameComplete action. /// </summary> /// <returns></returns> public async Task GameComplete(GameCompletePayload gameCompletePayload) { if (runnerStateService.GetEngine().ConnectionId != Context.ConnectionId) { await SendGameException( new GameException { ExceptionMessage = "Invalid engine connection, gameComplete could not be actioned." }); return; } Logger.LogInfo("RunnerHub", "Game Complete"); runnerStateService.GameCompletePayload = gameCompletePayload; var completePayload = runnerStateService.GameCompletePayload; await Clients.All.SendAsync("ReceiveGameComplete", JsonConvert.SerializeObject(completePayload)); var logger = runnerStateService.GetLogger(); if (logger != default) { await logger.Client.SendAsync("SaveLogs", completePayload); } await cloudIntegrationService.Announce(CloudCallbackType.Finished); }
private async Task OnSaveLogs(GameCompletePayload gameCompletePayload) { LogWriter.LogInfo("Logger", "Game Complete. Saving Logs..."); var finalLogDir = logDirectory; if (pushLogsToS3) { finalLogDir = $"{logDirectory}/logs"; var finalLogDirDetails = Directory.CreateDirectory(finalLogDir); } LogWriter.LogInfo("Logger", $"Saving Files into Directory: {finalLogDir}, Current Directory: {Directory.GetCurrentDirectory()}"); string gameExceptionFilePath = null; if (gameExceptionLog.Count > 0) { LogWriter.LogInfo("Logger", "Game Exception Log"); gameExceptionFilePath = WriteFileWithSerialisation( loggerConfig.GameExceptionLogFileName, finalLogDir, gameExceptionLog.ToArray()); } var logTime = $"{DateTime.Now:yyyy-MM-dd_hh-mm-ss}"; var stateFileName = matchStatusFileName ?? $"{loggerConfig.GameStateLogFileName}_{logTime}"; var gameStateFilePath = WriteFileWithSerialisation( stateFileName, finalLogDir, gameStateDtoLog); var gameCompleteFilePath = WriteFileWithSerialisation( $"{gameCompleteFileName ?? $"{loggerConfig.GameStateLogFileName}_{logTime}_GameComplete"}", finalLogDir, gameCompletePayload); LogWriter.LogInfo("Logger", "Logs Saved Successfully"); LogWriter.LogInfo("Logger", $"Log Directory: {logDirectory}, Current Directory: {Directory.GetCurrentDirectory()}"); if (pushLogsToS3) { try { await SaveLogsToS3(finalLogDir); } catch (Exception e) { LogWriter.LogError("AWS.S3", $"Upload failed with reason: {e.Message}"); } } var sideCarTimeout = Environment.GetEnvironmentVariable("WAIT_FOR_SIDECAR"); LogWriter.LogInfo( "Logger", $"Waiting for sidecar: {!string.IsNullOrWhiteSpace(sideCarTimeout)}, Waiting for: {sideCarTimeout}ms"); if (string.IsNullOrWhiteSpace(sideCarTimeout)) { await connection.InvokeAsync("GameLoggingComplete"); waitingForSideCar = false; return; } waitingForSideCar = true; Thread.Sleep(int.Parse(sideCarTimeout)); LogWriter.LogInfo("Logger", "Completed timeout for Sidecar"); if (!calledForDisconnect) { return; } await connection.InvokeAsync("GameLoggingComplete"); waitingForSideCar = false; }