Search in sources :

Example 1 with WorkflowStatus

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus in project conductor by Netflix.

the class SubWorkflow method execute.

@Override
public boolean execute(Workflow workflow, Task task, WorkflowExecutor provider) {
    String workflowId = task.getSubWorkflowId();
    if (StringUtils.isEmpty(workflowId)) {
        return false;
    }
    Workflow subWorkflow = provider.getWorkflow(workflowId, false);
    WorkflowStatus subWorkflowStatus = subWorkflow.getStatus();
    if (!subWorkflowStatus.isTerminal()) {
        return false;
    }
    updateTaskStatus(subWorkflow, task);
    return true;
}
Also used : Workflow(com.netflix.conductor.common.run.Workflow) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus)

Example 2 with WorkflowStatus

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus in project conductor by Netflix.

the class WorkflowExecutor method pauseWorkflow.

/**
 * @throws ApplicationException if the workflow cannot be paused
 */
public void pauseWorkflow(String workflowId) {
    try {
        executionLockService.acquireLock(workflowId, 60000);
        WorkflowStatus status = WorkflowStatus.PAUSED;
        Workflow workflow = executionDAOFacade.getWorkflowById(workflowId, false);
        if (workflow.getStatus().isTerminal()) {
            throw new ApplicationException(CONFLICT, "Workflow id " + workflowId + " has ended, status cannot be updated.");
        }
        if (workflow.getStatus().equals(status)) {
            // Already paused!
            return;
        }
        workflow.setStatus(status);
        executionDAOFacade.updateWorkflow(workflow);
    } finally {
        executionLockService.releaseLock(workflowId);
    }
}
Also used : SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus)

Example 3 with WorkflowStatus

use of com.netflix.conductor.common.run.Workflow.WorkflowStatus in project conductor by Netflix.

the class DeciderService method retry.

@VisibleForTesting
Optional<Task> retry(TaskDef taskDefinition, WorkflowTask workflowTask, Task task, Workflow workflow) throws TerminateWorkflowException {
    int retryCount = task.getRetryCount();
    if (taskDefinition == null) {
        taskDefinition = metadataDAO.getTaskDef(task.getTaskDefName());
    }
    final int expectedRetryCount = taskDefinition == null ? 0 : Optional.ofNullable(workflowTask).map(WorkflowTask::getRetryCount).orElse(taskDefinition.getRetryCount());
    if (!task.getStatus().isRetriable() || SystemTaskType.isBuiltIn(task.getTaskType()) || expectedRetryCount <= retryCount) {
        if (workflowTask != null && workflowTask.isOptional()) {
            return Optional.empty();
        }
        WorkflowStatus status;
        switch(task.getStatus()) {
            case CANCELED:
                status = WorkflowStatus.TERMINATED;
                break;
            case TIMED_OUT:
                status = WorkflowStatus.TIMED_OUT;
                break;
            default:
                status = WorkflowStatus.FAILED;
                break;
        }
        updateWorkflowOutput(workflow, task);
        throw new TerminateWorkflowException(task.getReasonForIncompletion(), status, task);
    }
    // retry... - but not immediately - put a delay...
    int startDelay;
    // If workflowTask has a retry policy, prefer it over taskDef
    if (workflowTask.getRetryLogic() != TaskDef.RetryLogic.UNSPECIFIED) {
        startDelay = getRetryDelayInSeconds(workflowTask.getRetryLogic(), workflowTask.getStartDelay(), task);
    } else {
        // TaskDef policy is unspecified
        if (taskDefinition.getRetryLogic() == TaskDef.RetryLogic.UNSPECIFIED) {
            // Constant value
            startDelay = taskDefinition.getRetryDelaySeconds();
        } else {
            startDelay = getRetryDelayInSeconds(taskDefinition.getRetryLogic(), taskDefinition.getRetryDelaySeconds(), task);
        }
    }
    task.setRetried(true);
    Task rescheduled = task.copy();
    rescheduled.setStartDelayInSeconds(startDelay);
    rescheduled.setCallbackAfterSeconds(startDelay);
    rescheduled.setRetryCount(task.getRetryCount() + 1);
    rescheduled.setRetried(false);
    rescheduled.setTaskId(IDGenerator.generate());
    rescheduled.setRetriedTaskId(task.getTaskId());
    rescheduled.setStatus(SCHEDULED);
    rescheduled.setPollCount(0);
    rescheduled.setInputData(new HashMap<>());
    rescheduled.getInputData().putAll(task.getInputData());
    rescheduled.setReasonForIncompletion(null);
    rescheduled.setSubWorkflowId(null);
    if (StringUtils.isNotBlank(task.getExternalInputPayloadStoragePath())) {
        rescheduled.setExternalInputPayloadStoragePath(task.getExternalInputPayloadStoragePath());
    } else {
        rescheduled.getInputData().putAll(task.getInputData());
    }
    if (workflowTask != null && workflow.getSchemaVersion() > 1) {
        Workflow workflowInstance = populateWorkflowAndTaskData(workflow);
        Map<String, Object> taskInput = parametersUtils.getTaskInputV2(workflowTask.getInputParameters(), workflowInstance, rescheduled.getTaskId(), taskDefinition);
        rescheduled.getInputData().putAll(taskInput);
    }
    externalizeTaskData(rescheduled);
    // for the schema version 1, we do not have to recompute the inputs
    return Optional.of(rescheduled);
}
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) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Workflow (com.netflix.conductor.common.run.Workflow)3 WorkflowStatus (com.netflix.conductor.common.run.Workflow.WorkflowStatus)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Task (com.netflix.conductor.common.metadata.tasks.Task)1 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)1 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)1