# 7 - Sleeping
In some circumstances it is necessary to wait for task to complete before proceeding. For example, in a banking system we might initiate a transfer with a 3rd party API, and then wait a period of time before we ask if it has completed.
DATP allows a pipeline to put itself to sleep using
the function instance.retryLater()
. After the specified interval the step is queued to be re-run. To allow the step to know how many times it has been restarted a retryCounter is incremented each time.
In this exercise we want a step that sleeps once and the proceeds, so we can sleep if the counter is zero, and continue if the counter is greater than zero.
Your mission
Copy
MySleepingStep.js
into myProject/steps.Register the step in app.js.
Add the step to myPipeline, replacing the existing delay step.
Restart the server by saving app.js again.
Run the test for myPipeline and watch the console output from the server.
In MONDAT you can press the Refresh button to follow the progress.
The Cache/Archive tab shows the state of the transaction as it progresses.
When a step puts the pipeline to sleep, it goes into hybernation. At the assigned time, the wakeup processor will add the transaction back to the queue for the node group.
Extra
Create another step, named "sleep10", that sleeps for 10 minutes.