use of org.jenkinsci.plugins.workflow.support.concurrent.Timeout in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method suspendAll.
@Restricted(DoNotUse.class)
@Terminator
public static void suspendAll() {
CpsFlowExecution exec = null;
try (Timeout t = Timeout.limit(3, TimeUnit.MINUTES)) {
// TODO some complicated sequence of calls to Futures could allow all of them to run in parallel
LOGGER.fine("starting to suspend all executions");
for (FlowExecution execution : FlowExecutionList.get()) {
if (execution instanceof CpsFlowExecution) {
LOGGER.log(Level.FINE, "waiting to suspend {0}", execution);
exec = (CpsFlowExecution) execution;
// Like waitForSuspension but with a timeout:
if (exec.programPromise != null) {
exec.programPromise.get(1, TimeUnit.MINUTES).scheduleRun().get(1, TimeUnit.MINUTES);
}
}
}
LOGGER.fine("finished suspending all executions");
} catch (Exception x) {
LOGGER.log(Level.WARNING, "problem suspending " + exec, x);
}
}
use of org.jenkinsci.plugins.workflow.support.concurrent.Timeout in project workflow-cps-plugin by jenkinsci.
the class CpsThread method runNextChunk.
/**
* Executes CPS code synchronously a little bit more, until it hits
* the point the workflow needs to be dehydrated.
*/
@SuppressWarnings("rawtypes")
@Nonnull
Outcome runNextChunk() {
assert program != null;
Outcome outcome;
final CpsThread old = CURRENT.get();
CURRENT.set(this);
try (Timeout timeout = Timeout.limit(5, TimeUnit.MINUTES)) {
LOGGER.log(FINE, "runNextChunk on {0}", resumeValue);
final Outcome o = resumeValue;
resumeValue = null;
outcome = program.run0(o, categories);
if (outcome.getAbnormal() != null) {
LOGGER.log(FINE, "ran and produced error", outcome.getAbnormal());
} else {
LOGGER.log(FINE, "ran and produced {0}", outcome);
}
if (outcome.getNormal() instanceof ThreadTask) {
// if an execution in the thread safepoint is requested, deliver that
ThreadTask sc = (ThreadTask) outcome.getNormal();
ThreadTaskResult r = sc.eval(this);
if (r.resume != null) {
// yield, then keep evaluating the CPS code
resumeValue = r.resume;
} else {
// break but with a different value
outcome = r.suspend;
}
}
} finally {
CURRENT.set(old);
}
if (promise != null) {
if (outcome.isSuccess())
promise.set(outcome.getNormal());
else {
try {
promise.setException(outcome.getAbnormal());
} catch (Error e) {
if (e == outcome.getAbnormal()) {
// affects other places that use SettableFuture
;
} else {
throw e;
}
}
}
promise = null;
}
return outcome;
}
Aggregations