/** Persist the execution if we are set up to save the execution with every step. */ void saveExecutionIfDurable() { if (this.getDurabilityHint().isPersistWithEveryStep()) { saveOwner(); } }
/** Report a fatal error in the VM. */ void croak(Throwable t) { setResult(Result.FAILURE); onProgramEnd(new Outcome(null, t)); cleanUpHeap(); try { saveOwner(); } catch (Exception ex) { LOGGER.log(Level.WARNING, "Failed to persist WorkflowRun after noting a serious failure for run: " + owner, ex); } }
saveOwner(); } catch (Exception ex) { LOGGER.log(Level.WARNING, "Error saving build for "+this, ex);
LOGGER.log(Level.FINE, "Flow has FlowEndNode, but is not marked as done, fixing this for"+this); done = true; saveOwner();
final SettableFuture<CpsThreadGroup> f = SettableFuture.create(); programPromise = f; saveOwner(); // Ensures we've saves the WorkFlowRun at least once with initial state g.runner.submit(new Runnable() { @Override
head.setNewHead(end); saveOwner();
execution.onProgramEnd(o); try { this.execution.saveOwner(); } catch (Exception ex) { LOGGER.log(Level.WARNING, "Error saving execution for "+this.getExecution(), ex);
@Override public void evaluate() throws Throwable { WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, "durableAgainstClean", FlowDurabilityHint.PERFORMANCE_OPTIMIZED); Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint()); logStart[0] = JenkinsRule.getLog(run); if (run.getExecution() instanceof CpsFlowExecution) { // Pause and unPause to force persistence CpsFlowExecution cpsFlow = (CpsFlowExecution)(run.getExecution()); cpsFlow.pause(true); long timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && !cpsFlow.isPaused()) { Thread.sleep(100L); } nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution())); nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR); cpsFlow.pause(false); timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && cpsFlow.isPaused()) { Thread.sleep(100L); } // Ensures we're marked as can-not-resume cpsFlow.persistedClean = false; cpsFlow.saveOwner(); } } });
/** Simulates case where done flag was not persisted. */ @Test public void completedButWrongDoneStatus() throws Exception { final int[] build = new int[1]; final Result[] executionAndBuildResult = new Result[2]; story.thenWithHardShutdown( j -> { WorkflowRun run = runBasicBuild(j, DEFAULT_JOBNAME, build); String finalId = run.getExecution().getCurrentHeads().get(0).getId(); // Hack but deletes the FlowNodeStorage from disk CpsFlowExecution cpsExec = (CpsFlowExecution)(run.getExecution()); cpsExec.done = false; cpsExec.saveOwner(); executionAndBuildResult[0] = ((CpsFlowExecution)(run.getExecution())).getResult(); executionAndBuildResult[1] = run.getResult(); }); story.then(j-> { WorkflowJob r = j.jenkins.getItemByFullName(DEFAULT_JOBNAME, WorkflowJob.class); WorkflowRun run = r.getBuildByNumber(build[0]); assertCompletedCleanly(run); Assert.assertEquals(Result.SUCCESS, run.getResult()); assertResultMatchExecutionAndRun(run, executionAndBuildResult); }); }