I have an ADF pipeline with a for each loop on files and performing some activity that should only run for the downtime hours. I am starting it using a trigger and want it to gracefully exit execution after 2 hours, whether it is done looping through all files or not.
Is there a way to configure it in ADF?
2
Answers
One way is to have a separate pipeline which contains a wait activity(2hr) followed by a web activity.
The web activity can call the data factory api to send a cancel run request.
Refer :
How-to-cancel-a-pipeline-run
Creating the web activity by referring the web-activity and preferably using msi as the authentication.
Another method is using logic app, it already builtin tasks to create a pipeline trigger, cancel it etc.
One way to do this is checking the time difference in each iteration in an if activity and if it’s True, then call the web activity to cancel the pipeline using the REST API.
Before the pipeline activities, create a set variable activity with
@utcnow()
.Inside the ForEach, after your activity use an if activity with the below condition.
The above conditon checks the time difference between current time and the
mytime
variable is 2 hours (120 minutes) or not.If it results
True
, add a web activity in the True activities to cancel the Pipeline run with REST API using current pipeline run id.You can go through this blog by @Andy Leonard to know about canceling the current pipeline using web activity inside the ForEach.