Class StepExecution
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractStepExecutionImpl
,GeneralNonBlockingStepExecution
,SynchronousNonBlockingStepExecution
,SynchronousStepExecution
Step
, and provides insights into what's going on
asynchronously and aborting the activity if need be.
StepExecution
s are persisted whenever used to run an asynchronous operation.
- Author:
- Kohsuke Kawaguchi, Jesse Glick
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Deprecated.Avoid Guice.protected
StepExecution
(StepContext context) If manually created,StepContext
must be passed in. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.common.util.concurrent.ListenableFuture<?>
applyAll
(com.google.common.base.Function<StepExecution, Void> f) Apply the given function to all the active runningStepExecution
s in the system.static <T extends StepExecution>
com.google.common.util.concurrent.ListenableFuture<?>Applies only to the specific subtypes.boolean
Allows a step to indicate thatAsynchronousExecution.blocksRestart()
should be true.May be overridden to provide specific information about what a step is currently doing, for diagnostic purposes.final String
getStatusBounded
(long timeout, TimeUnit unit) LikegetStatus()
but more robust.void
onResume()
Called whenStepExecution
is brought back into memory after restart.abstract boolean
start()
Start execution of something and report the end result back to the given callback.void
May be called if someone asks a running step to abort.
-
Constructor Details
-
StepExecution
Deprecated.Avoid Guice.Default constructor used by injection. -
StepExecution
If manually created,StepContext
must be passed in.
-
-
Method Details
-
getContext
-
start
Start execution of something and report the end result back to the given callback.Arguments are passed when instantiating steps.
This method will run in the CPS VM thread and as such should not perform I/O or block. Use
SynchronousNonBlockingStepExecution
orGeneralNonBlockingStepExecution
as needed.- Returns:
- true if the execution of this step has synchronously completed before this method returns.
It is the callee's responsibility to set the return value via
StepContext.onSuccess(Object)
orFutureCallback.onFailure(Throwable)
. false if the asynchronous execution has started and thatStepContext
will be notified when the result comes in. (Note that the nature of asynchrony is such that it is possible for theStepContext
to be already notified before this method returns.) - Throws:
Exception
- if any exception is thrown,Step
is assumed to have completed abnormally synchronously (as ifFutureCallback.onFailure(java.lang.Throwable)
is called and the method returned true.)
-
stop
May be called if someone asks a running step to abort.Just like
Thread.interrupt()
, the step might not honor the request immediately. Multiple stop requests might be sent. It is always responsible for callingStepContext.onSuccess(Object)
or (more likely)FutureCallback.onFailure(Throwable)
eventually, whether or not it was asked to stop.The default behavior is to call
FutureCallback.onFailure(java.lang.Throwable)
immediately. This may be overridden by non-block-scoped steps which wish to halt some processing prior to failing the step, or even to send a cancellation signal to some process but leave the step running until that is handled gracefully. Block-scoped steps which merely call their bodies generally need not override this method, as the interrupt will be sent to the step(s) actually running at the time (so no special call toBodyExecution.cancel(Throwable)
is needed), though an override may be necessary if it is possible for there to be no body currently running.This method is meant to be used by
FlowExecution
, not called from UI or other human requests to pause. UseBodyExecution.cancel(Throwable)
for programmatic cancellation of bodies.- Parameters:
cause
- Contextual information that lets the step know what resulted in stopping an executing step, passed in the hope that this will assist diagnostics.- Throws:
Exception
-
onResume
public void onResume()Called whenStepExecution
is brought back into memory after restart. Convenient for re-establishing the polling.Currently not permitted to throw exceptions, but may report errors via
FutureCallback.onFailure(java.lang.Throwable)
.- See Also:
-
getStatus
May be overridden to provide specific information about what a step is currently doing, for diagnostic purposes. Typical format should be a short, lowercase phrase. It should not be localized as this is intended for use by developers as well as users. May include technical details about Jenkins internals if relevant.- Returns:
- current status, or null if unimplemented
- See Also:
-
blocksRestart
public boolean blocksRestart()Allows a step to indicate thatAsynchronousExecution.blocksRestart()
should be true. Typically this would be true ifgetStatus()
indicates that the step is in the middle of something active, as opposed to waiting for an external event or a body to complete.Note that activity in the CPS VM thread automatically blocks restart, so overriding this is only necessary for steps using a background thread, such as
SynchronousNonBlockingStepExecution
orGeneralNonBlockingStepExecution
.- Returns:
- false by default
-
getStatusBounded
LikegetStatus()
but more robust. Waits a most a given amount of time for the result, and handlesRuntimeException
s.- Parameters:
timeout
- maximum amount of time to spendunit
- time unit
-
applyAll
public static com.google.common.util.concurrent.ListenableFuture<?> applyAll(com.google.common.base.Function<StepExecution, Void> f) Apply the given function to all the active runningStepExecution
s in the system.- Returns:
- Future object that signals when the function application is complete.
- See Also:
-
applyAll
public static <T extends StepExecution> com.google.common.util.concurrent.ListenableFuture<?> applyAll(Class<T> type, com.google.common.base.Function<T, Void> f) Applies only to the specific subtypes.
-