use of com.walmartlabs.concord.runner.engine.EventConfiguration in project concord by walmartlabs.
the class Main method executeProcess.
private void executeProcess(String instanceId, CheckpointManager checkpointManager, Path baseDir, Map<String, Object> processCfg) throws ExecutionException {
// get active profiles from the request data
Collection<String> activeProfiles = getActiveProfiles(processCfg);
// load the project
ProjectDefinition project = loadProject(baseDir);
// read the list of metadata variables
Set<String> metaVariables = getMetaVariables(processCfg);
// event recording processCfg
EventConfiguration eventCfg = getEventCfg(processCfg);
Engine engine = engineFactory.create(project, baseDir, activeProfiles, metaVariables, eventCfg);
Map<String, Object> resumeCheckpointReq = null;
while (true) {
Collection<Event> resultEvents;
// check if we need to resume the process from a saved point
Set<String> eventNames = StateManager.readResumeEvents(baseDir);
if (eventNames == null || eventNames.isEmpty()) {
// running fresh
// let's check if there are some saved variables (e.g. from the parent process)
Variables vars = readSavedVariables(baseDir);
resultEvents = start(engine, vars, processCfg, instanceId, baseDir);
} else {
if (eventNames.size() > 1) {
throw new IllegalStateException("Runtime v1 supports resuming for only one event at the time. Got: " + eventNames);
}
String eventName = eventNames.iterator().next();
resultEvents = resume(engine, processCfg, instanceId, baseDir, eventName);
}
Event checkpointEvent = resultEvents.stream().filter(e -> e.getPayload() instanceof Map).filter(e -> getCheckpointId(e) != null).findFirst().orElse(null);
// found a checkpoint, resume the process immediately
if (checkpointEvent != null) {
checkpointManager.process(getCheckpointId(checkpointEvent), getCorrelationId(checkpointEvent), checkpointEvent.getName(), baseDir);
// clear arguments
if (resumeCheckpointReq == null) {
resumeCheckpointReq = new HashMap<>(processCfg);
resumeCheckpointReq.remove(Constants.Request.ARGUMENTS_KEY);
}
processCfg = resumeCheckpointReq;
} else {
// no checkpoints, stop the execution and wait for an external event
return;
}
}
}
Aggregations