# Name: CancelRemainingTasks_sample.py
# Description: This script attempts to run a child job. If there is an exception
# and the child job fails to run a step, the Cancel Remaining Tasks tool is
# called to cancel the remaining tasks for parent job.
# Import System Modules
import arcpy
# Check Out Extensions
arcpy.CheckOutExtension('Foundation')
arcpy.CheckOutExtension('JTX')
# Setting Local Variables
job_id = 15
workflow_database = r'C:\Data\Workflows\Testing.jtc'
#Connect to the workflow database
connection = arcpy.wmx.Connect(workflow_database)
#Get a Job for Execution
job = connection.getJob(job_id)
# Execute the job
try:
result = job.executeStep()
#Raised when a step in the workflow encounters an execution error
except wmx.WorkflowExecutionStepError as e:
print ("Step failed to execute, canceling remaining tasks.")
# get the id of the parent job
parent_id = job.parent
# If an exeception happens, call the Cancel Remaining Tasks tool to cancel
# all the remaining tasks for the parent job.
arcpy.topographic.CancelRemainingTasks(parent_id, workflow_database)
# Check In Extensions
arcpy.CheckInExtension('Foundation')
arcpy.CheckInExtension('JTX')