private void OnResetJobStates() { try { var task = Task.Run(async() => { duplicates.Cancel(); var jobs = await _repository.GetJobsByState(JobState.Running); if (jobs?.Count > 0) { for (int i = 0; i < jobs.Count; i++) { jobs[i].JobState = JobState.Idle; await _repository.Update(jobs[i]); } } }); task.Wait(); } catch (Exception ex) { _logger.Error(ex); } finally { } }
private async Task OnJobConfigSetState(Job job) { try { var config = await _repository.GetJobConfiguration(job.Id); if (job.JobState == Jobs.JobState.Idle) { // when idle we check config if we should start the job if (OnShouldStartIdleJob(config)) { job.JobState = Jobs.JobState.Starting; await _repository.Update(job); } } else if (job.JobState == Jobs.JobState.Stopping) { // when stopping we stop the task for the job OnStopJob(job, config); } else if (job.JobState == Jobs.JobState.Running) { // when running we check against start time and max runtime in minutes if (OnShouldStopRunningJob(job, config)) { job.JobState = Jobs.JobState.Stopping; await _repository.Update(job); } } else if (job.JobState == Jobs.JobState.Starting) { // when starting we should start the task for this job OnStartJob(job, config); } } catch (Exception ex) { _logger.Error(ex); } }