public static Set<WorkflowInstance> getTimedOutInstances(Map<WorkflowId, Workflow> workflows, List<InstanceState> activeStates, Instant instant, TimeoutConfig ttl) { return activeStates.parallelStream() .filter(entry -> { final Optional<Workflow> workflowOpt = Optional.ofNullable(workflows.get(entry.workflowInstance().workflowId())); return hasTimedOut(workflowOpt, entry.runState(), instant, ttl.ttlOf(entry.runState().state())); }) .map(InstanceState::workflowInstance) .collect(toSet()); }
public static ConcurrentMap<String, Long> getResourceUsage(boolean globalConcurrencyEnabled, List<InstanceState> activeStates, Set<WorkflowInstance> timedOutInstances, WorkflowResourceDecorator resourceDecorator, Map<WorkflowId, Workflow> workflows) { return activeStates.parallelStream() .filter(entry -> !timedOutInstances.contains(entry.workflowInstance())) .filter(entry -> isConsumingResources(entry.runState().state())) .flatMap(instanceState -> pairWithResources(globalConcurrencyEnabled, instanceState, workflows, resourceDecorator)) .collect(groupingByConcurrent( ResourceWithInstance::resource, ConcurrentHashMap::new, counting())); }
private static Stream<ResourceWithInstance> pairWithResources(boolean globalConcurrencyEnabled, InstanceState instanceState, Map<WorkflowId, Workflow> workflows, WorkflowResourceDecorator resourceDecorator) { final Optional<Workflow> workflowOpt = Optional.ofNullable(workflows.get(instanceState.workflowInstance().workflowId())); final Set<String> workflowResources = workflowResources(globalConcurrencyEnabled, workflowOpt); return workflowOpt .map(workflow -> resourceDecorator.decorateResources( instanceState.runState(), workflow.configuration(), workflowResources)) .orElse(workflowResources).stream() .map(resource -> ResourceWithInstance.create(resource, instanceState)); }
private void sendDequeue(InstanceState instanceState, Set<String> resourceIds) { final WorkflowInstance workflowInstance = instanceState.workflowInstance(); final RunState state = instanceState.runState(); if (state.data().tries() == 0) { LOG.info("Executing {}", workflowInstance); } else { LOG.info("Executing {}, retry #{}", workflowInstance, state.data().tries()); } stateManager.receiveIgnoreClosed(Event.dequeue(workflowInstance, resourceIds), instanceState.runState().counter()); }
instanceState.runState(), workflow.configuration(), workflowResourceRefs)) .orElse(workflowResourceRefs); Event.runError(instanceState.workflowInstance(), String.format("Referenced resources not found: %s", unknownResources)), instanceState.runState().counter()); return; LOG.debug("Resource limit reached for instance, not dequeueing: {}: exhausted resources={}", instanceState.workflowInstance(), depletedResources); MessageUtil.emitResourceLimitReachedMessage(stateManager, instanceState.runState(), depletedResources); return; stateManager.receiveIgnoreClosed(Event.retryAfter(instanceState.workflowInstance(), blocker.get().delay().toMillis()), instanceState.runState().counter()); LOG.debug("Dequeue rescheduled: {}: {}", instanceState.workflowInstance(), blocker.get()); return;