private void Execute(Worker worker, Task task) { string taskType = task.TaskDefName; try { if (!worker.PreAck(task)) { m_logger.LogDebug($"Worker {taskType} decided not to ack the task {task.TaskId}"); return; } if (!client.Ack(task.TaskId, worker.Identity)) { //WorkflowTaskMetrics.ackFailed(worker.getTaskDefName()); m_logger.LogError($"Ack failed for {taskType}, id {task.TaskId}"); return; } } catch (Exception e) { m_logger.LogError($"ack exception for {worker.TaskDefName} : {e.Message}"); //WorkflowTaskMetrics.ackException(worker.getTaskDefName(), e); return; } //Stopwatch sw = WorkflowTaskMetrics.executionTimer(worker.getTaskDefName()); TaskResult result = null; try { m_logger.LogDebug($"Executing task {nameof(task)} on worker {nameof(worker)}"); result = worker.Execute(task); result.WorkflowInstanceId = task.WorkflowInstanceId; result.TaskId = task.TaskId; } catch (Exception e) { m_logger.LogError($"Unable to execute task {task} : {e.Message}"); if (result == null) { task.Status = Status.FAILED; result = new TaskResult(task); } handleException(e, result, worker, false, task); } finally { //sw.stop(); } m_logger.LogDebug($"Task {task.TaskId} executed by worker {nameof(worker)} with status {task.Status}"); UpdateWithRetry(m_updateRetryCount, task, result, worker); }
private void UpdateWithRetry(int count, Task task, TaskResult result, Worker worker) { if (count < 0) { worker.OnErrorUpdate(task); return; } try { client.UpdateTask(result); } catch (Exception t) { //WorkflowTaskMetrics.updateTaskError(worker.getTaskDefName(), t); m_logger.LogError(new EventId(1), t, $"Unable to update {result} on count {count}"); Thread.Sleep(m_sleepWhenRetry); UpdateWithRetry(--count, task, result, worker); } }
private void handleException(Exception t, TaskResult result, Worker worker, bool updateTask, Task task) { //WorkflowTaskMetrics.executionException(worker.getTaskDefName(), t); result.Status = Status.FAILED; result.ReasonForIncompletion = "Error while executing the task: " + t; result.Logs.Add(t.StackTrace); UpdateWithRetry(m_updateRetryCount, task, result, worker); }