/// <summary> /// Populate Tasks using the Task Creator as a source /// </summary> /// <param name="job">Job to add Tasks to</param> /// <returns></returns> private async Task PopulateTasksAsync(JobEntity job) { _log.Info($"JobManager.PopulateTasksAsync, jobId-{job.Id}"); foreach (var taskType in TaskUtilityFactory.SupportedTaskTypes) { var taskCreator = TaskUtilityFactory.GetTaskCreator(taskType); taskCreator.CreateTasks(job); } await _jobAndTaskService.PersistTasksAsync(job); await _jobAndTaskService.UpdateJobStatusAsync(job, JobStatusEnum.TasksCreated); }
/// <summary> /// Endpoint Services to create tasks against /// </summary> /// <param name="tasksToSupport">List of Services to run as tasks</param> private void SetTaskUtilityFactory(IEnumerable <TaskTypeEnum> tasksToSupport) { foreach (var task in tasksToSupport) { switch (task) { case TaskTypeEnum.TimeSeries: TaskUtilityFactory.AddTaskUtility(new TaskUtility(task, new TimeSeriesEndPoint(_timeSeriesDataStore), new TimeSeriesTaskCreator())); break; case TaskTypeEnum.Alarm: TaskUtilityFactory.AddTaskUtility(new TaskUtility(task, new AlarmEndPoint(_alarmDataStore), new AlarmTaskCreator())); break; } } }
/// <summary> /// process all incomplete tasks in a job, if no apropriate endpoints available, the process result will be false /// </summary> /// <param name="job">the job entity</param> /// <returns>if all tasks are completed</returns> private async Task ProcessJobAsync(JobEntity job) { _log.Info($"JobManager.ProcessJobAsync, jobId-{job.Id}"); bool jobProcessSuccessful = true; await _jobAndTaskService.UpdateJobStatusAsync(job, JobStatusEnum.Executing); foreach (var task in job.Tasks.Where(t => !t.IsCompleted)) { var endpoint = TaskUtilityFactory.GetEndPoint(task.TaskType); if (endpoint != null) { await endpoint.RunAsync(task.TaskUrl) .ContinueWith(async(a) => { if (a.Result) { await _jobAndTaskService.MarkTaskCompleteAsync(task); } else { jobProcessSuccessful = false; } }); } else { //can't handle this task jobProcessSuccessful = false; } } if (jobProcessSuccessful) { await _jobAndTaskService.UpdateJobStatusAsync(job, JobStatusEnum.Success); } else { await _jobAndTaskService.UpdateJobStatusAsync(job, JobStatusEnum.Error); } }