public void ExecuteCalcJob([NotNull] MessageFromServerToClient job, [NotNull] CalcExecutor calcExecutor, [NotNull] RequestSocket client) { var cdp = new CalcDirectoryPreparer(_mySettings, _logger, _threadId); cdp.Run(); HouseCreationAndCalculationJob hcj = null; if (!string.IsNullOrWhiteSpace(job.HouseJobStr)) { hcj = JsonConvert.DeserializeObject <HouseCreationAndCalculationJob>(job.HouseJobStr); if (hcj.CalcSpec == null) { hcj.CalcSpec = JsonCalcSpecification.MakeDefaultsForProduction(); } hcj.CalcSpec.OutputDirectory = "Results"; string jsonFileName = Path.Combine(_mySettings.ClientSettings.LPGCalcDirectory, "calcjob.json"); string correctedJob = JsonConvert.SerializeObject(hcj, Formatting.Indented); File.WriteAllText(jsonFileName, correctedJob); calcExecutor.Run(hcj); } else { _logger.Info("Client #" + _threadId + ": Got a task with an exe, not real, waiting 5s", _threadId); Thread.Sleep(5000); } ReportFinishedCalcJob(job, client, hcj); }
public void TryRun() { try { _logger.Info("Started the client " + _threadId.Name + " and connecting to " + _mySettings.ServerIP, _threadId); using (var client = new RequestSocket()) { client.Connect(_mySettings.ServerIP); _logger.Info("connected to " + _mySettings.ServerIP, _threadId); while (_mySettings.ContinueRunning) { var calcExecutor = new CalcExecutor(_threadId, _logger, _mySettings); while (calcExecutor.IsWorkingDirFull()) { ReportDiskFullAndWait(client); if (!_mySettings.ContinueRunning) { return; } } if (_mySettings.RequestNewJobs) { var job = RequestNewJobFromServer(client); if (job == null) { Thread.Sleep(5000); continue; } // ReSharper disable once SwitchStatementMissingSomeCases switch (job.ServerResponse) { case ServerResponseEnum.NothingToDo: _logger.Info("Client #" + _threadId.Name + ": Nothing to do, waiting 60s.", _threadId); Thread.Sleep(60000); break; case ServerResponseEnum.ServeCalcJob: { if (!AreAllFilesIdentical(job) && !RequestAndSaveNewLPGFiles(client)) { _logger.Error("Failed to synchronize the lpg", _threadId); continue; } ExecuteCalcJob(job, calcExecutor, client); break; } default: throw new DistSimException("Unknown command"); } } else { _logger.Info("Client #" + _threadId.Name + ": Not requesting new jobs, waiting 5s.", _threadId); Thread.Sleep(5000); } } } _logger.Info("Stopped client " + _threadId.Name, _threadId); } catch (Exception ex) { _logger.Exception(ex, "general failure", _threadId); ThreadException = ex; throw; } }