Search in sources :

Example 71 with Task

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

the class TestDeciderService method testGetTaskByRef.

@Test
public void testGetTaskByRef() {
    Workflow workflow = new Workflow();
    Task t1 = new Task();
    t1.setReferenceTaskName("ref");
    t1.setSeq(0);
    t1.setStatus(Status.TIMED_OUT);
    Task t2 = new Task();
    t2.setReferenceTaskName("ref");
    t2.setSeq(1);
    t2.setStatus(Status.FAILED);
    Task t3 = new Task();
    t3.setReferenceTaskName("ref");
    t3.setSeq(2);
    t3.setStatus(Status.COMPLETED);
    workflow.getTasks().add(t1);
    workflow.getTasks().add(t2);
    workflow.getTasks().add(t3);
    Task task = workflow.getTaskByRefName("ref");
    assertNotNull(task);
    assertEquals(Status.COMPLETED, task.getStatus());
    assertEquals(t3.getSeq(), task.getSeq());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 72 with Task

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

the class TestDeciderService method testIsResponseTimedOut.

@Test
public void testIsResponseTimedOut() {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("test_rt");
    taskDef.setResponseTimeoutSeconds(10);
    Task task = new Task();
    task.setTaskDefName("test_rt");
    task.setStatus(Status.IN_PROGRESS);
    task.setTaskId("aa");
    task.setTaskType(TaskType.TASK_TYPE_SIMPLE);
    task.setUpdateTime(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
    assertTrue(deciderService.isResponseTimedOut(taskDef, task));
    // verify that sub workflow tasks are not response timed out
    task.setTaskType(TaskType.TASK_TYPE_SUB_WORKFLOW);
    assertFalse(deciderService.isResponseTimedOut(taskDef, task));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 73 with Task

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

the class ExecutionService method getLastPollTask.

public Task getLastPollTask(String taskType, String workerId, String domain) {
    List<Task> tasks = poll(taskType, workerId, domain, POLL_COUNT_ONE, POLLING_TIMEOUT_IN_MS);
    if (tasks.isEmpty()) {
        logger.debug("No Task available for the poll: /tasks/poll/{}?{}&{}", taskType, workerId, domain);
        return null;
    }
    Task task = tasks.get(0);
    ackTaskReceived(task);
    logger.debug("The Task {} being returned for /tasks/poll/{}?{}&{}", task, taskType, workerId, domain);
    return task;
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task)

Example 74 with Task

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

the class ExecutionService method poll.

public List<Task> poll(String taskType, String workerId, String domain, int count, int timeoutInMilliSecond) {
    if (timeoutInMilliSecond > MAX_POLL_TIMEOUT_MS) {
        throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Long Poll Timeout value cannot be more than 5 seconds");
    }
    String queueName = QueueUtils.getQueueName(taskType, domain, null, null);
    List<String> taskIds = new LinkedList<>();
    List<Task> tasks = new LinkedList<>();
    try {
        taskIds = queueDAO.pop(queueName, count, timeoutInMilliSecond);
    } catch (Exception e) {
        logger.error("Error polling for task: {} from worker: {} in domain: {}, count: {}", taskType, workerId, domain, count, e);
        Monitors.error(this.getClass().getCanonicalName(), "taskPoll");
        Monitors.recordTaskPollError(taskType, domain, e.getClass().getSimpleName());
    }
    for (String taskId : taskIds) {
        try {
            Task task = getTask(taskId);
            if (task == null || task.getStatus().isTerminal()) {
                // Remove taskId(s) without a valid Task/terminal state task from the queue
                queueDAO.remove(queueName, taskId);
                logger.debug("Removed task: {} from the queue: {}", taskId, queueName);
                continue;
            }
            if (executionDAOFacade.exceedsInProgressLimit(task)) {
                // Postpone this message, so that it would be available for poll again.
                queueDAO.postpone(queueName, taskId, task.getWorkflowPriority(), queueTaskMessagePostponeSeconds);
                logger.debug("Postponed task: {} in queue: {} by {} seconds", taskId, queueName, queueTaskMessagePostponeSeconds);
                continue;
            }
            TaskDef taskDef = task.getTaskDefinition().isPresent() ? task.getTaskDefinition().get() : null;
            if (task.getRateLimitPerFrequency() > 0 && executionDAOFacade.exceedsRateLimitPerFrequency(task, taskDef)) {
                // Postpone this message, so that it would be available for poll again.
                queueDAO.postpone(queueName, taskId, task.getWorkflowPriority(), queueTaskMessagePostponeSeconds);
                logger.debug("RateLimit Execution limited for {}:{}, limit:{}", taskId, task.getTaskDefName(), task.getRateLimitPerFrequency());
                continue;
            }
            task.setStatus(Status.IN_PROGRESS);
            if (task.getStartTime() == 0) {
                task.setStartTime(System.currentTimeMillis());
                Monitors.recordQueueWaitTime(task.getTaskDefName(), task.getQueueWaitTime());
            }
            // reset callbackAfterSeconds when giving the task to the worker
            task.setCallbackAfterSeconds(0);
            task.setWorkerId(workerId);
            task.setPollCount(task.getPollCount() + 1);
            executionDAOFacade.updateTask(task);
            tasks.add(task);
        } catch (Exception e) {
            // db operation failed for dequeued message, re-enqueue with a delay
            logger.warn("DB operation failed for task: {}, postponing task in queue", taskId, e);
            Monitors.recordTaskPollError(taskType, domain, e.getClass().getSimpleName());
            queueDAO.postpone(queueName, taskId, 0, queueTaskMessagePostponeSeconds);
        }
    }
    executionDAOFacade.updateTaskLastPoll(taskType, domain, workerId);
    Monitors.recordTaskPoll(queueName);
    return tasks;
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) LinkedList(java.util.LinkedList) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 75 with Task

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

the class TestSimpleActionProcessor method testCompleteTaskByTaskId.

@Test
public void testCompleteTaskByTaskId() throws Exception {
    TaskDetails taskDetails = new TaskDetails();
    taskDetails.setWorkflowId("${workflowId}");
    taskDetails.setTaskId("${taskId}");
    Action action = new Action();
    action.setAction(Type.complete_task);
    action.setComplete_task(taskDetails);
    Object payload = objectMapper.readValue("{\"workflowId\":\"workflow_1\", \"taskId\":\"task_1\"}", Object.class);
    Task task = new Task();
    task.setTaskId("task_1");
    task.setReferenceTaskName("testTask");
    when(workflowExecutor.getTask(eq("task_1"))).thenReturn(task);
    actionProcessor.execute(action, payload, "testEvent", "testMessage");
    ArgumentCaptor<TaskResult> argumentCaptor = ArgumentCaptor.forClass(TaskResult.class);
    verify(workflowExecutor).updateTask(argumentCaptor.capture());
    assertEquals(Status.COMPLETED, argumentCaptor.getValue().getStatus());
    assertEquals("testMessage", argumentCaptor.getValue().getOutputData().get("conductor.event.messageId"));
    assertEquals("testEvent", argumentCaptor.getValue().getOutputData().get("conductor.event.name"));
    assertEquals("workflow_1", argumentCaptor.getValue().getOutputData().get("workflowId"));
    assertEquals("task_1", argumentCaptor.getValue().getOutputData().get("taskId"));
}
Also used : Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) Task(com.netflix.conductor.common.metadata.tasks.Task) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Aggregations

Task (com.netflix.conductor.common.metadata.tasks.Task)357 Workflow (com.netflix.conductor.common.run.Workflow)249 Test (org.junit.Test)248 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)227 HashMap (java.util.HashMap)147 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)121 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)110 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)95 UserTask (com.netflix.conductor.tests.utils.UserTask)73 Map (java.util.Map)53 LinkedList (java.util.LinkedList)51 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)45 List (java.util.List)45 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)39 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)38 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29 Collectors (java.util.stream.Collectors)29 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)28