Search in sources :

Example 11 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class TaskServiceImpl method updateTask.

@Override
public void updateTask(TaskServicePb.UpdateTaskRequest req, StreamObserver<TaskServicePb.UpdateTaskResponse> response) {
    try {
        TaskResult task = PROTO_MAPPER.fromProto(req.getResult());
        taskService.updateTask(task);
        response.onNext(TaskServicePb.UpdateTaskResponse.newBuilder().setTaskId(task.getTaskId()).build());
        response.onCompleted();
    } catch (Exception e) {
        GRPC_HELPER.onError(response, e);
    }
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 12 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class AbstractProtoMapper method fromProto.

public TaskResult fromProto(TaskResultPb.TaskResult from) {
    TaskResult to = new TaskResult();
    to.setWorkflowInstanceId(from.getWorkflowInstanceId());
    to.setTaskId(from.getTaskId());
    to.setReasonForIncompletion(from.getReasonForIncompletion());
    to.setCallbackAfterSeconds(from.getCallbackAfterSeconds());
    to.setWorkerId(from.getWorkerId());
    to.setStatus(fromProto(from.getStatus()));
    Map<String, Object> outputDataMap = new HashMap<String, Object>();
    for (Map.Entry<String, Value> pair : from.getOutputDataMap().entrySet()) {
        outputDataMap.put(pair.getKey(), fromProto(pair.getValue()));
    }
    to.setOutputData(outputDataMap);
    if (from.hasOutputMessage()) {
        to.setOutputMessage(fromProto(from.getOutputMessage()));
    }
    to.setRetryDelaySeconds(from.getRetryDelaySeconds());
    return to;
}
Also used : HashMap(java.util.HashMap) Value(com.google.protobuf.Value) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Object(java.lang.Object) String(java.lang.String) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class TaskResourceTest method testUpdateTask.

@Test
public void testUpdateTask() throws Exception {
    TaskResult taskResult = new TaskResult();
    taskResult.setStatus(TaskResult.Status.COMPLETED);
    taskResult.setTaskId("123");
    when(mockTaskService.updateTask(any(TaskResult.class))).thenReturn("123");
    assertEquals("123", taskResource.updateTask(taskResult));
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 14 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class TaskPollExecutor method updateWithRetry.

private void updateWithRetry(int count, Task task, TaskResult result, Worker worker) {
    try {
        String updateTaskDesc = String.format("Retry updating task result: %s for task: %s in worker: %s", result.toString(), task.getTaskDefName(), worker.getIdentity());
        String evaluatePayloadDesc = String.format("Evaluate Task payload for task: %s in worker: %s", task.getTaskDefName(), worker.getIdentity());
        String methodName = "updateWithRetry";
        TaskResult finalResult = new RetryUtil<TaskResult>().retryOnException(() -> {
            TaskResult taskResult = result.copy();
            taskClient.evaluateAndUploadLargePayload(taskResult, task.getTaskType());
            return taskResult;
        }, null, null, count, evaluatePayloadDesc, methodName);
        new RetryUtil<>().retryOnException(() -> {
            taskClient.updateTask(finalResult);
            return null;
        }, null, null, count, updateTaskDesc, methodName);
    } catch (Exception e) {
        worker.onErrorUpdate(task);
        MetricsContainer.incrementTaskUpdateErrorCount(worker.getTaskDefName(), e);
        LOGGER.error(String.format("Failed to update result: %s for task: %s in worker: %s", result.toString(), task.getTaskDefName(), worker.getIdentity()), e);
    }
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 15 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class TaskServiceImpl method failTask.

/**
 * Updates the task with FAILED status; On exception, fails the workflow.
 * @param task
 * @param errorMsg
 */
private void failTask(Task task, String errorMsg) {
    try {
        TaskResult taskResult = new TaskResult();
        taskResult.setStatus(TaskResult.Status.FAILED);
        taskResult.setTaskId(task.getTaskId());
        taskResult.setWorkflowInstanceId(task.getWorkflowInstanceId());
        taskResult.setReasonForIncompletion(errorMsg);
        executionService.updateTask(taskResult);
    } catch (Exception e) {
        LOGGER.error("Unable to fail task: {} in workflow: {}", task.getTaskId(), task.getWorkflowInstanceId(), e);
        executionService.terminateWorkflow(task.getWorkflowInstanceId(), "Failed to ack task: " + task.getTaskId());
    }
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Aggregations

TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)41 Test (org.junit.Test)29 Task (com.netflix.conductor.common.metadata.tasks.Task)22 Workflow (com.netflix.conductor.common.run.Workflow)17 TaskClient (com.netflix.conductor.client.http.TaskClient)11 Worker (com.netflix.conductor.client.worker.Worker)11 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)8 HashMap (java.util.HashMap)8 StartWorkflowRequest (com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest)7 UserTask (com.netflix.conductor.tests.utils.UserTask)7 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)6 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)4 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)4 Map (java.util.Map)4 ConductorClientException (com.netflix.conductor.client.exceptions.ConductorClientException)2 Action (com.netflix.conductor.common.metadata.events.EventHandler.Action)2 StartWorkflow (com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow)2 TaskDetails (com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails)2