Search in sources :

Example 66 with TaskResult

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

the class TaxCalculator method execute.

@Override
public TaskResult execute(Task task) {
    String zipCode = (String) task.getInputData().get("zipCode");
    if (zipCode == null || StringUtils.isEmpty(zipCode)) {
        task.setStatus(Task.Status.FAILED);
        task.setReasonForIncompletion("missing zip code");
    }
    Number amount = (Number) task.getInputData().get("amount");
    if (amount == null) {
        task.setStatus(Task.Status.FAILED);
        task.setReasonForIncompletion("missing amount");
    }
    // 10% tax
    BigDecimal tax = new BigDecimal(amount.doubleValue()).multiply(new BigDecimal(0.1));
    task.getOutputData().put("tax", tax);
    task.setStatus(Task.Status.COMPLETED);
    return new TaskResult(task);
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) BigDecimal(java.math.BigDecimal)

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