Search in sources :

Example 31 with TaskResult

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

the class FedExWorker 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 32 with TaskResult

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

the class ImageConvertResizeWorker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    try {
        String fileLocation = (String) task.getInputData().get("fileLocation");
        Integer width = (Integer) task.getInputData().get("outputWidth");
        Integer height = (Integer) task.getInputData().get("outputHeight");
        String outputFormat = (String) task.getInputData().get("outputFormat");
        String outputFileName = "/tmp/" + UUID.randomUUID().toString() + "." + outputFormat;
        String s3BucketName = "image-processing-orkes";
        resizeImage(fileLocation, width, height, outputFileName);
        String url = S3Utils.uploadToS3(outputFileName, Regions.US_EAST_1, s3BucketName);
        result.setStatus(TaskResult.Status.COMPLETED);
        result.addOutputData("fileLocation", url);
        result.addOutputData("outputWidth", width);
        result.addOutputData("outputHeight", height);
        result.addOutputData("outputFormat", outputFormat);
    } 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 : StringWriter(java.io.StringWriter) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) PrintWriter(java.io.PrintWriter)

Example 33 with TaskResult

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

the class ImageEffectWorker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    try {
        String fileLocation = (String) task.getInputData().get("fileLocation");
        String recipeName = ((String) task.getInputData().get("recipe")).toLowerCase();
        RECIPE recipe = validateRecipeNames(recipeName);
        Map<String, Object> recipeParameters = (Map<String, Object>) task.getInputData().get("recipeParameters");
        String fileExtension = Files.getFileExtension(fileLocation);
        String outputFileName = "/tmp/" + UUID.randomUUID().toString() + "-" + recipe.name() + "." + fileExtension;
        if (recipe == RECIPE.SEPIA) {
            Integer sepiaIntensityThreshold = ((Integer) recipeParameters.get("sepiaIntensityThreshold"));
            sepia(fileLocation, sepiaIntensityThreshold, outputFileName);
        } else if (recipe == RECIPE.VIBRANT) {
            Integer vibrance = ((Integer) recipeParameters.get("vibrance"));
            vibrant(fileLocation, vibrance, outputFileName);
        }
        String s3BucketName = "image-processing-orkes";
        String url = S3Utils.uploadToS3(outputFileName, Regions.US_EAST_1, s3BucketName);
        result.setStatus(TaskResult.Status.COMPLETED);
        result.addOutputData("fileLocation", url);
        result.addOutputData("recipe", recipe);
        result.addOutputData("recipeParameters", recipeParameters);
    } 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 : StringWriter(java.io.StringWriter) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 34 with TaskResult

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

the class TaskCallbackWorker method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    result.addOutputData("result" + runCount.incrementAndGet(), "Run Count: " + runCount.get());
    result.log("Running for " + runCount.get());
    if (runCount.get() % 5 == 0) {
        // Check DB if things are completed
        result.setStatus(TaskResult.Status.COMPLETED);
    } else {
        // If still running then post updates
        result.setStatus(TaskResult.Status.IN_PROGRESS);
        result.setCallbackAfterSeconds(3);
    }
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 35 with TaskResult

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

the class UPSWorker 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)

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