use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.
the class ProcessQueueGaugeModule method configure.
@Override
@SuppressWarnings("rawtypes")
protected void configure() {
Provider<ProcessQueueDao> queueDaoProvider = getProvider(ProcessQueueDao.class);
// create the base gauge that caches all individual values
Gauge<Map<String, Integer>> base = new CachedGauge<Map<String, Integer>>(15, TimeUnit.SECONDS) {
@Override
protected Map<String, Integer> loadValue() {
return queueDaoProvider.get().getStatistics();
}
};
Multibinder<GaugeProvider> gauges = Multibinder.newSetBinder(binder(), GaugeProvider.class);
gauges.addBinding().toInstance(createBaseProvider(base));
for (ProcessStatus s : ProcessStatus.values()) {
gauges.addBinding().toInstance(create(base, s.toString()));
}
gauges.addBinding().toInstance(create(base, ProcessQueueDao.ENQUEUED_NOW_METRIC));
}
use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.
the class ProcessQueueManager method enqueue.
/**
* Updates an existing record, moving the process into the ENQUEUED status.
*/
public boolean enqueue(Payload payload) {
ProcessKey processKey = payload.getProcessKey();
ProcessStatus s = queueDao.getStatus(processKey);
if (s == null) {
throw new ProcessException(processKey, "Process not found: " + processKey);
}
if (s == ProcessStatus.CANCELLED) {
// (e.g. it was a process in an "exclusive" group)
return false;
}
if (!TO_ENQUEUED_STATUSES.contains(s)) {
// something's wrong (e.g. someone tried to change the process' status directly in the DB and was unlucky)
throw new ProcessException(processKey, "Invalid process status: " + s);
}
Set<String> tags = payload.getHeader(Payload.PROCESS_TAGS);
OffsetDateTime startAt = PayloadUtils.getStartAt(payload);
Map<String, Object> requirements = PayloadUtils.getRequirements(payload);
Long processTimeout = getProcessTimeout(payload);
Long suspendTimeout = getSuspendTimeout(payload);
Set<String> handlers = payload.getHeader(Payload.PROCESS_HANDLERS);
Map<String, Object> meta = getMeta(getCfg(payload));
Imports imports = payload.getHeader(Payload.IMPORTS);
ExclusiveMode exclusive = PayloadUtils.getExclusive(payload);
String runtime = payload.getHeader(Payload.RUNTIME);
List<String> dependencies = payload.getHeader(Payload.DEPENDENCIES);
return queueDao.txResult(tx -> {
boolean updated = queueDao.enqueue(tx, processKey, tags, startAt, requirements, processTimeout, handlers, meta, imports, exclusive, runtime, dependencies, suspendTimeout, TO_ENQUEUED_STATUSES);
if (updated) {
notifyStatusChange(tx, processKey, ProcessStatus.ENQUEUED);
}
return updated;
});
}
use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.
the class CustomFormServiceV1 method continueSession.
private Response continueSession(UriInfo uriInfo, HttpHeaders headers, ProcessKey processKey, String formName, Map<String, Object> data) {
// TODO locking
Form form = assertForm(processKey, formName);
// TODO constants
Map<String, Object> opts = form.getOptions();
boolean yield = opts != null && (boolean) opts.getOrDefault("yield", false);
Path dst = cfg.getBaseDir().resolve(processKey.toString()).resolve(formName);
Path formDir = dst.resolve(FORM_DIR_NAME);
try {
Map<String, Object> m = new HashMap<>();
try {
m = FormUtils.convert(new ExternalFileFormValidatorLocale(processKey, formName, stateManager), form, data);
FormSubmitResult r = formService.submit(processKey, formName, m);
if (r.isValid()) {
if (yield) {
// this was the last "interactive" form. The process will continue in "background"
// and users should get a success page.
writeData(formDir, success(form, m));
} else {
while (true) {
ProcessStatus s = queueDao.getStatus(processKey);
if (s == ProcessStatus.SUSPENDED) {
String nextFormId = formService.nextFormId(processKey);
if (nextFormId == null) {
writeData(formDir, success(form, m));
break;
} else {
FormSessionResponse nextSession = startSession(processKey, nextFormId);
return redirectTo(nextSession.getUri());
}
} else if (s == ProcessStatus.FAILED || s == ProcessStatus.CANCELLED || s == ProcessStatus.TIMED_OUT) {
writeData(formDir, processFailed(form, m));
break;
} else if (s == ProcessStatus.FINISHED) {
writeData(formDir, success(form, m));
break;
}
try {
// TODO exp back off?
Thread.sleep(STATUS_REFRESH_DELAY);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
} else {
writeData(formDir, prepareData(form, m, r.getErrors()));
}
} catch (ValidationException e) {
ValidationError err = ValidationError.of(e.getField().getName(), e.getMessage());
FormData d = prepareData(form, m, Collections.singletonList(err));
writeData(formDir, d);
}
} catch (Exception e) {
throw new ConcordApplicationException("Error while submitting a form", e);
}
return redirectToForm(uriInfo, headers, processKey, formName);
}
use of com.walmartlabs.concord.server.sdk.ProcessStatus in project concord by walmartlabs.
the class ProjectProcessResource method proceed.
private Response proceed(PartialProcessKey processKey) {
ProcessEntry entry = processQueueManager.get(processKey);
if (entry == null) {
throw new ConcordApplicationException("Process not found: " + processKey, Status.NOT_FOUND);
}
ProcessKey pk = new ProcessKey(entry.instanceId(), entry.createdAt());
ProcessStatus s = entry.status();
if (s == ProcessStatus.FAILED || s == ProcessStatus.CANCELLED || s == ProcessStatus.TIMED_OUT) {
return processError(processKey, "Process failed: " + s, null);
} else if (s == ProcessStatus.FINISHED) {
return processFinished(processKey);
} else if (s == ProcessStatus.SUSPENDED) {
String nextFormId = nextFormId(pk);
if (nextFormId == null) {
return processError(processKey, "Invalid process state: no forms found", null);
}
String url = "/#/process/" + entry.instanceId() + "/wizard";
return Response.status(Status.MOVED_PERMANENTLY).header(HttpHeaders.LOCATION, url).build();
} else {
Map<String, Object> args = prepareArgumentsForInProgressTemplate(entry);
return responseTemplates.inProgressWait(Response.ok(), args).build();
}
}
Aggregations