use of com.walmartlabs.concord.runtime.v2.model.TaskCall 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);
}
use of com.walmartlabs.concord.runtime.v2.model.TaskCall in project concord by walmartlabs.
the class EventRecordingExecutionListener method afterCommand.
@Override
public Result afterCommand(Runtime runtime, VM vm, State state, ThreadId threadId, Command cmd) {
if (!eventConfiguration.recordEvents()) {
return Result.CONTINUE;
}
if (!(cmd instanceof StepCommand)) {
return Result.CONTINUE;
}
StepCommand<?> s = (StepCommand<?>) cmd;
if (s.getStep() instanceof TaskCall || s.getStep() instanceof Expression) {
return Result.CONTINUE;
}
ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
Location loc = s.getStep().getLocation();
Map<String, Object> m = new HashMap<>();
m.put("processDefinitionId", ProcessDefinitionUtils.getCurrentFlowName(pd, s.getStep()));
m.put("fileName", loc.fileName());
m.put("line", loc.lineNum());
m.put("column", loc.column());
m.put("description", getDescription(s.getStep()));
m.put("correlationId", s.getCorrelationId());
ProcessEventRequest req = new ProcessEventRequest();
// TODO constants
req.setEventType("ELEMENT");
req.setData(m);
req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
try {
eventsApi.event(processInstanceId.getValue(), req);
} catch (ApiException e) {
log.warn("afterCommand [{}] -> error while sending an event to the server: {}", cmd, e.getMessage());
}
return Result.CONTINUE;
}
use of com.walmartlabs.concord.runtime.v2.model.TaskCall in project concord by walmartlabs.
the class ContextImpl method reentrantSuspend.
@Override
public void reentrantSuspend(String eventName, Map<String, Serializable> taskState) {
Step step = execution().currentStep();
if (!(step instanceof TaskCall)) {
throw new IllegalStateException("Calling 'suspendResume' is allowed only in task calls. Current step: " + (step != null ? step.getClass() : "n/a"));
}
state.peekFrame(currentThreadId).push(new TaskSuspendCommand(correlationId, LogUtils.getContext(), eventName, (TaskCall) step, taskState));
}
use of com.walmartlabs.concord.runtime.v2.model.TaskCall 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();
}
Aggregations