Search in sources :

Example 61 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class ImageEffectsPreForkWorker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    try {
        List<String> fileLocations = (List<String>) task.getInputData().get("fileLocations");
        List<Map<String, Object>> recipeInfos = (List<Map<String, Object>>) task.getInputData().get("recipeInfos");
        List<WorkflowTask> dynamicTasks = Lists.newArrayList();
        Map<String, Object> dynamicTasksInput = Maps.newHashMap();
        int i = 0;
        String dynamicTaskName = "image_effect";
        for (String fileLocation : fileLocations) {
            for (Map<String, Object> recipeInfo : recipeInfos) {
                String recipe = (String) recipeInfo.get("recipe");
                Map<String, Object> recipeParameters = (Map<String, Object>) recipeInfo.get("recipeParameters");
                String fileName = Paths.get(new URI(fileLocation).getPath()).getFileName().toString();
                String taskRefName = String.format("%s_%s_%s_%d", dynamicTaskName, fileName, recipe, i++);
                WorkflowTask dynamicTask = new WorkflowTask();
                dynamicTask.setName(dynamicTaskName);
                dynamicTask.setTaskReferenceName(taskRefName);
                dynamicTasks.add(dynamicTask);
                Map<String, Object> dynamicTaskInput = Maps.newHashMap();
                dynamicTaskInput.put("fileLocation", fileLocation);
                dynamicTaskInput.put("recipe", recipe);
                dynamicTaskInput.put("recipeParameters", recipeParameters);
                dynamicTasksInput.put(taskRefName, dynamicTaskInput);
            }
        }
        result.setStatus(TaskResult.Status.COMPLETED);
        String currentTimeOnServer = Instant.now().toString();
        result.log("This is a test log at time: " + currentTimeOnServer);
        result.addOutputData("dynamicTasks", dynamicTasks);
        result.addOutputData("dynamicTasksInput", dynamicTasksInput);
    } catch (Exception e) {
        e.printStackTrace();
        result.setStatus(TaskResult.Status.FAILED);
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        result.log(sw.getBuffer().toString());
    }
    return result;
}
Also used : WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) URI(java.net.URI) StringWriter(java.io.StringWriter) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) List(java.util.List) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 62 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class Task5Worker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    result.setStatus(TaskResult.Status.COMPLETED);
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 63 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class Task6Worker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    result.setStatus(TaskResult.Status.COMPLETED);
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 64 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class Task8Worker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    result.setStatus(TaskResult.Status.COMPLETED);
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 65 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class AlwaysFailingTaskWorker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    result.addOutputData("outputVal", "This task always fails (for testing)");
    result.setStatus(TaskResult.Status.FAILED);
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Aggregations

TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)66 Test (org.junit.Test)29 Task (com.netflix.conductor.common.metadata.tasks.Task)22 Workflow (com.netflix.conductor.common.run.Workflow)17 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)13 TaskClient (com.netflix.conductor.client.http.TaskClient)11 Worker (com.netflix.conductor.client.worker.Worker)11 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 Map (java.util.Map)7 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)6 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 List (java.util.List)5 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)4 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2