/** * Pauses the execution. * * @return * {@link Future} object that represents the actual suspension of the CPS VM. * When the {@link #pause()} method is called, CPS VM might be still executing. */ public Future<?> pause() { paused.set(true); // CPS VM might have a long queue in its task list, so to properly ensure // that the execution has actually suspended, call scheduleRun() excessively return scheduleRun(); }
/** * If the execution is {@link #isPaused()}, cancel the pause state. */ public void unpause() { if (paused.getAndSet(false)) { // some threads might have became executable while we were pausing. scheduleRun(); } else { LOGGER.warning("were not paused to begin with"); } }
/** * Waits for the workflow to move into the SUSPENDED state. */ public void waitForSuspension() throws InterruptedException, ExecutionException { if (programPromise==null) return; // the execution has already finished and we are not loading program state anymore CpsThreadGroup g = programPromise.get(); // TODO occasionally tests fail here with RejectedExecutionException, apparently because the runner has been shut down; should we just ignore that? g.scheduleRun().get(); }
/** * Schedules the execution of this thread from the last {@linkplain Continuable#suspend(Object)} point. * * @return * Future that promises the completion of the next {@link #runNextChunk()}. */ public Future<Object> resume(Outcome v) { if (resumeValue != null) { return Futures.immediateFailedFuture(new IllegalStateException("Already resumed with " + resumeValue)); } resumeValue = v; promise = SettableFuture.create(); group.scheduleRun(); return promise; }
public void onSuccess(Unmarshaller u) { pickleFutures = null; try { CpsFlowExecution old = PROGRAM_STATE_SERIALIZATION.get(); PROGRAM_STATE_SERIALIZATION.set(CpsFlowExecution.this); try { CpsThreadGroup g = (CpsThreadGroup) u.readObject(); result.set(g); try { if (g.isPaused()) { owner.getListener().getLogger().println("Still paused"); } else { owner.getListener().getLogger().println("Ready to run at " + new Date()); // In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart. g.scheduleRun(); } } catch (IOException x) { LOGGER.log(Level.WARNING, null, x); } } catch (Throwable t) { onFailure(t); } finally { PROGRAM_STATE_SERIALIZATION.set(old); } } finally { r.close(); } }
LOGGER.log(Level.FINER, "Waiting for Pipeline to go to sleep for shutdown: "+execution); try { exec.programPromise.get(1, TimeUnit.MINUTES).scheduleRun().get(1, TimeUnit.MINUTES); LOGGER.log(Level.FINER, " Pipeline went to sleep OK: "+execution); } catch (InterruptedException | TimeoutException ex) {