Search in sources :

Example 1 with TaskCallOptions

use of com.walmartlabs.concord.runtime.v2.model.TaskCallOptions in project concord by walmartlabs.

the class TaskCallCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    Frame frame = state.peekFrame(threadId);
    frame.pop();
    Context ctx = runtime.getService(Context.class);
    TaskProviders taskProviders = runtime.getService(TaskProviders.class);
    ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
    TaskCall call = getStep();
    String taskName = call.getName();
    Task t = taskProviders.createTask(ctx, taskName);
    if (t == null) {
        throw new IllegalStateException("Task not found: '" + taskName + "'");
    }
    TaskCallInterceptor interceptor = runtime.getService(TaskCallInterceptor.class);
    CallContext callContext = CallContext.builder().taskName(taskName).correlationId(ctx.execution().correlationId()).currentStep(getStep()).processDefinition(ctx.execution().processDefinition()).build();
    TaskCallOptions opts = Objects.requireNonNull(call.getOptions());
    Variables input = new MapBackedVariables(VMUtils.prepareInput(expressionEvaluator, ctx, opts.input(), opts.inputExpression()));
    TaskResult result;
    try {
        result = interceptor.invoke(callContext, Method.of(t, "execute", Collections.singletonList(input)), () -> t.execute(input));
    } catch (TaskException e) {
        result = TaskResult.fail(e.getCause());
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TaskCallUtils.processTaskResult(runtime, ctx, taskName, opts, result);
}
Also used : CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) Frame(com.walmartlabs.concord.svm.Frame) TaskCall(com.walmartlabs.concord.runtime.v2.model.TaskCall) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator) CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)

Example 2 with TaskCallOptions

use of com.walmartlabs.concord.runtime.v2.model.TaskCallOptions in project concord by walmartlabs.

the class TaskCallStepSerializer method serialize.

@Override
public void serialize(TaskCall value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeStartObject();
    TaskCallOptions o = Objects.requireNonNull(value.getOptions());
    if ("log".equals(value.getName())) {
        gen.writeObjectField("log", o.input().get("msg"));
    } else {
        gen.writeObjectField("task", value.getName());
        writeNotEmptyObjectField("in", o.input(), gen);
        writeNotEmptyObjectField("in", o.inputExpression(), gen);
    }
    writeNotEmptyObjectField("out", o.out(), gen);
    writeNotEmptyObjectField("out", o.outExpr(), gen);
    if (o.withItems() != null) {
        WithItems items = Objects.requireNonNull(o.withItems());
        writeWithItems(items, gen);
    }
    writeLoop(o.loop(), gen);
    if (o.retry() != null) {
        gen.writeObjectField("retry", o.retry());
    }
    writeNotEmptyObjectField("error", o.errorSteps(), gen);
    writeNotEmptyObjectField("meta", o.meta(), gen);
    if (o.ignoreErrors()) {
        gen.writeObjectField("ignoreErrors", o.ignoreErrors());
    }
    gen.writeEndObject();
}
Also used : TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) WithItems(com.walmartlabs.concord.runtime.v2.model.WithItems)

Aggregations

TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)2 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)1 WithItems (com.walmartlabs.concord.runtime.v2.model.WithItems)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)1 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)1 Frame (com.walmartlabs.concord.svm.Frame)1