Search in sources :

Example 1 with ExclusiveMode

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;
}
Also used : UUID(java.util.UUID) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 2 with ExclusiveMode

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;
}
Also used : ProcessQueueEntry(com.walmartlabs.concord.server.process.queue.ProcessQueueEntry) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode)

Example 3 with ExclusiveMode

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;
    });
}
Also used : ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) Imports(com.walmartlabs.concord.imports.Imports) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode) OffsetDateTime(java.time.OffsetDateTime)

Aggregations

ExclusiveMode (com.walmartlabs.concord.runtime.v2.model.ExclusiveMode)3 Imports (com.walmartlabs.concord.imports.Imports)1 ProcessQueueEntry (com.walmartlabs.concord.server.process.queue.ProcessQueueEntry)1 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 OffsetDateTime (java.time.OffsetDateTime)1 UUID (java.util.UUID)1