public override ConductorTask ExecuteTask(ConductorTask task) { LogManager.GetCurrentClassLogger().Info("Running sample worker - executing a task"); task.Status = ConductorTaskStatus.COMPLETED; task.Output.Add("result", "Nothing to return"); task.AddLog("Nothing to do"); return(task); }
public async Task <ConductorTaskResult> Execute(ConductorTask task) { if (task is null) { throw new ArgumentNullException(nameof(task)); } WorkflowInstanceId = task.WorkflowInstanceId; var conductorContext = new { WorkflowInstanceId, task.TaskId, TaskName = task.WorkflowTask.Name, TaskType, task.InputData }; using (LogContext.PushProperty("ConductorContext", conductorContext, true)) { try { Logger.LogInformation("Starting task {TaskType} ({TaskId})", TaskType, task.TaskId); if (task.InputData != null) { InputData = new ConductorTaskData(task.InputData); } var stopwatch = Stopwatch.StartNew(); var output = await OnExecute(); stopwatch.Stop(); Logger.LogInformation("Finished task {TaskType} {TaskId} in {Milliseconds}ms", TaskType, task.TaskId, stopwatch.ElapsedMilliseconds); if (output == null) { output = new ConductorTaskData(); } output["correlationId"] = WorkflowInstanceId; return(task.Completed(output)); } catch (Exception ex) { Logger.LogError(ex, "Failed to execute {TaskType}", TaskType); return(ex.GetType() == typeof(WorkflowTaskFailedException) ? task.Failed(ex.Message, null) : task.FailedWithTerminalError(ex, null)); } } }
public static ConductorTaskResult Completed(this ConductorTask task, ConductorTaskData?outputData = null, ICollection <ConductorTaskLog> logs = null) { return(new ConductorTaskResult { WorkflowInstanceId = task.WorkflowInstanceId, TaskId = task.TaskId, Status = TaskResultStatus.COMPLETED, OutputData = outputData, Logs = logs }); }
public static ConductorTaskResult InProgress(this ConductorTask task, ConductorTaskData?outputData = null, ICollection <ConductorTaskLog> logs = null) { return(new ConductorTaskResult { WorkflowInstanceId = task.WorkflowInstanceId, TaskId = task.TaskId, Status = TaskResultStatus.IN_PROGRESS, OutputData = outputData, Logs = logs }); }
public static ConductorTaskResult FailedWithTerminalError(this ConductorTask task, Exception exception, ConductorTaskData?outputData = null, ICollection <ConductorTaskLog> logs = null) { return(new ConductorTaskResult { WorkflowInstanceId = task.WorkflowInstanceId, TaskId = task.TaskId, Status = TaskResultStatus.FAILED_WITH_TERMINAL_ERROR, ReasonForIncompletion = exception.ToString(), OutputData = outputData, Logs = logs }); }
public static ConductorTaskResult Failed(this ConductorTask task, string errorMessage, ConductorTaskData?outputData = null, ICollection <ConductorTaskLog> logs = null) { return(new ConductorTaskResult { WorkflowInstanceId = task.WorkflowInstanceId, TaskId = task.TaskId, Status = TaskResultStatus.FAILED, ReasonForIncompletion = errorMessage, OutputData = outputData, Logs = logs }); }