Run On Demand¶
[1]:
from ctm_python_client.core.comm import Environment
from aapi import *
The run_on_demand()
method in the Control-M Python Client allows you to execute individual jobs, folders, or subfolders dynamically without using Workflow. You do not need to deploy the jobs to the Control-M/EM database and the User Daily job does not need to trigger them. This is useful for event-driven job executions.
This guide demonstrates how to use run_on_demand()
with the Job
, Folder
, and SubFolder
classes.
Requires Control-M/EM version 9.0.21.200
Code Example:¶
[ ]:
import time
# Step 1: Define the Job, Folder, Sub-Folder
demand_job = JobCommand('HelloJob', command='echo Hello')
demand_sub_folder = SubFolder("TestSubFolder", job_list=[demand_job])
demand_folder = Folder("TestFolder", job_list=[demand_job])
# Step 2: Define an Environment
env = Environment.create_onprem(host='controlm', username='***', password='****')
# Step 3: Run the Job On Demand
run_demand_job = demand_job.run_on_demand(
environment=env,
run_as='user',
controlm_server='ControlM'
)
time.sleep(4)
run_demand_job.print_output('HelloJob')
# Step 4: Run the SubFolder On Demand
run_demand_sub_folder = demand_sub_folder.run_on_demand(
environment=env,
run_as='user',
controlm_server='ControlM'
)
time.sleep(4)
run_demand_sub_folder.print_statuses()
# Step 5: Run the Folder On Demand
run_demand_folder = demand_folder.run_on_demand(
environment=env,
run_as='user',
controlm_server='ControlM'
)
time.sleep(4)
run_demand_folder.print_statuses()
+ echo Hello
Hello
Run Status
--------------------------------------------------
run_on_demand928 .................. Ended OK
HelloJob ...................... Ended OK
Run Status
--------------------------------------------------
TestFolder ........................ Ended OK
HelloJob .......................... Ended OK
Additional Notes:¶
Ensure that the Control-M/EM version is 9.0.21.200 or higher. Older versions not support the
run_on_demand()
method.Folder
s andSubfolder
s must include at least oneJob
. If aFolder
orSubFolder
does not contain any jobs, an exception will be raised with the error:"Run is not allowed for JSON without jobs"
The
run_as
user must have the necessary permissions in Control-M.The
controlm_server
parameter specifies the Control-M server responsible for execution.