Search in sources :

Example 1 with Service

use of com.netflix.conductor.annotations.Service in project conductor by Netflix.

the class MetadataServiceImpl method registerTaskDef.

/**
 * @param taskDefinitions Task Definitions to register
 */
@Service
public void registerTaskDef(List<TaskDef> taskDefinitions) {
    for (TaskDef taskDefinition : taskDefinitions) {
        taskDefinition.setCreatedBy(WorkflowContext.get().getClientApp());
        taskDefinition.setCreateTime(System.currentTimeMillis());
        taskDefinition.setUpdatedBy(null);
        taskDefinition.setUpdateTime(null);
        metadataDAO.createTaskDef(taskDefinition);
    }
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Service(com.netflix.conductor.annotations.Service)

Example 2 with Service

use of com.netflix.conductor.annotations.Service in project conductor by Netflix.

the class TaskServiceImpl method ackTaskReceived.

/**
 * Ack Task is received.
 *
 * @param taskId Id of the task
 * @return `true|false` if task if received or not
 */
@Service
public boolean ackTaskReceived(String taskId) {
    LOGGER.debug("Ack received for task: {}", taskId);
    String ackTaskDesc = "Ack Task with taskId: " + taskId;
    String ackTaskOperation = "ackTaskReceived";
    AtomicBoolean ackResult = new AtomicBoolean(false);
    try {
        new RetryUtil<>().retryOnException(() -> {
            ackResult.set(executionService.ackTaskReceived(taskId));
            return null;
        }, null, null, 3, ackTaskDesc, ackTaskOperation);
    } catch (Exception e) {
        // Fail the task and let decide reevaluate the workflow, thereby preventing workflow being stuck from transient ack errors.
        String errorMsg = String.format("Error when trying to ack task %s", taskId);
        LOGGER.error(errorMsg, e);
        Task task = executionService.getTask(taskId);
        Monitors.recordAckTaskError(task.getTaskType());
        failTask(task, errorMsg);
        ackResult.set(false);
    }
    return ackResult.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Task(com.netflix.conductor.common.metadata.tasks.Task) Service(com.netflix.conductor.annotations.Service)

Example 3 with Service

use of com.netflix.conductor.annotations.Service in project conductor by Netflix.

the class MetadataServiceImpl method updateWorkflowDef.

/**
 * @param workflowDefList Workflow definitions to be updated.
 */
@Service
public void updateWorkflowDef(List<WorkflowDef> workflowDefList) {
    for (WorkflowDef workflowDef : workflowDefList) {
        workflowDef.setUpdateTime(System.currentTimeMillis());
        metadataDAO.updateWorkflowDef(workflowDef);
    }
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Service(com.netflix.conductor.annotations.Service)

Example 4 with Service

use of com.netflix.conductor.annotations.Service in project conductor by Netflix.

the class MetadataServiceImpl method updateTaskDef.

/*
     * @param taskDefinition Task Definition to be updated
     */
@Service
public void updateTaskDef(TaskDef taskDefinition) {
    TaskDef existing = metadataDAO.getTaskDef(taskDefinition.getName());
    if (existing == null) {
        throw new ApplicationException(Code.NOT_FOUND, "No such task by name " + taskDefinition.getName());
    }
    taskDefinition.setUpdatedBy(WorkflowContext.get().getClientApp());
    taskDefinition.setUpdateTime(System.currentTimeMillis());
    metadataDAO.updateTaskDef(taskDefinition);
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Service(com.netflix.conductor.annotations.Service)

Example 5 with Service

use of com.netflix.conductor.annotations.Service in project conductor by Netflix.

the class TaskServiceImpl method poll.

/**
 * Poll for a task of a certain type.
 *
 * @param taskType Task name
 * @param workerId Id of the workflow
 * @param domain   Domain of the workflow
 * @return polled {@link Task}
 */
@Service
public Task poll(String taskType, String workerId, String domain) {
    LOGGER.debug("Task being polled: /tasks/poll/{}?{}&{}", taskType, workerId, domain);
    Task task = executionService.getLastPollTask(taskType, workerId, domain);
    if (task != null) {
        LOGGER.debug("The Task {} being returned for /tasks/poll/{}?{}&{}", task, taskType, workerId, domain);
    }
    Monitors.recordTaskPollCount(taskType, domain, 1);
    return task;
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) Service(com.netflix.conductor.annotations.Service)

Aggregations

Service (com.netflix.conductor.annotations.Service)10 BulkResponse (com.netflix.conductor.service.common.BulkResponse)5 Task (com.netflix.conductor.common.metadata.tasks.Task)2 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)2 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)1 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1