use of com.walmartlabs.concord.runtime.v2.model.ExclusiveMode in project concord by walmartlabs.
the class ExclusiveGroupProcessor method process.
@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
ExclusiveMode exclusive = PayloadUtils.getExclusive(payload);
if (exclusive == null) {
return chain.process(payload);
}
UUID projectId = payload.getHeader(Payload.PROJECT_ID);
if (projectId == null) {
return chain.process(payload);
}
ModeProcessor processor = processors.get(exclusive.mode());
if (processor == null) {
return chain.process(payload);
}
logManager.info(payload.getProcessKey(), "Process' exclusive group: {}", exclusive.group());
boolean canContinue = processor.process(payload, exclusive);
if (canContinue) {
return chain.process(payload);
}
return payload;
}
use of com.walmartlabs.concord.runtime.v2.model.ExclusiveMode in project concord by walmartlabs.
the class ExclusiveProcessFilter method findProcess.
@Override
protected List<UUID> findProcess(DSLContext tx, ProcessQueueEntry item, List<ProcessQueueEntry> startingProcesses) {
UUID projectId = item.projectId();
ExclusiveMode exclusive = item.exclusive();
if (projectId == null || exclusive == null) {
return Collections.emptyList();
}
boolean isWaitMode = exclusive.mode() == ExclusiveMode.Mode.wait;
if (!isWaitMode) {
return Collections.emptyList();
}
List<UUID> result = new ArrayList<>(dao.findProcess(tx, item, exclusive.group()));
for (ProcessQueueEntry p : startingProcesses) {
if (projectId.equals(p.projectId()) && groupEquals(exclusive, p.exclusive())) {
result.add(p.key().getInstanceId());
}
}
return result;
}
use of com.walmartlabs.concord.runtime.v2.model.ExclusiveMode 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;
});
}
Aggregations