{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Job and Folder Properties" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from aapi import *" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Allowed arguments for both Folder, SubFolder and Jobs:\n", "\n", "- **application**: Descriptive name for a set of related Jobs, Folders or SubFolders\n", "- **sub_application**: Descriptive name for a set of related Jobs, Folders or SubFolders with a same application\n", "- **run_as** : The OS user responsible for running a job (or all jobs in a folder or subfolder). By default, jobs are run by the user account where the Control-M/Agent is installed. To specify a diferent user, the agent must be running as root\n", "- **days_keep_active** : Defines the number of days to keep a job if the job did not run at its scheduled date. You can set this property for a Job, Folder, or SubFolder. Jobs in a folder are kept until the maximum DaysKeepActive value for any of the jobs in the folder has passed. This enables you to retrieve job status of all the jobs in the folder\n", "- **confirm** : Defines a job, folder, or subfolder that requires user confirmation\n", "- **created_by**: Specifies the Control‑M user responsible for job definitions. You can define this property for a Job object or Folder object\n", "- **description** : Description of th Job, Folder or SubFolder\n", "- **priority** : Defines the priority that a job has over other jobs. You can set this property for a Job, Folder, or SubFolder\n", "- **run_as_dummy** : (boolean) Runs any job as a dummy job\n", "- **retroactive_order** : (boolean) Orders a job retroactively to make up for days on which the job did not run. For example, Control-M was down for two days due to a hardware issue; as soon as jobs can run again, this job is scheduled retroactively to run an additional two times, to make up for the days that Control-M was inactive\n", "- **rerun** : See below `Rerun` section\n", "- **time_zone** : Adds the time zone to jobs, folder, or subfolder. Time zones should be defined at least 48 hours before the intended execution date. We recommend to define the same time zone for all jobs in a folder\n", "- **variables** : list of variables in a key, value format. See below `Variables`\n", "- **when** : See below `When` section\n", "- **if_list** : List of `If` objects. See below `If` section\n", "- **notify_list** List of `Notify` objects. See below `Notify`" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "folder = Folder('SampleFolder',\n", " controlm_server='ctmserver',\n", " site_standard='sitestd',\n", " business_fields=[{'Department': 'HR'}, {'Company': 'BMC'}],\n", " order_method=Folder.OrderMethod.Manual,\n", " application='ApplicationName',\n", " sub_application='SubApplication',\n", " run_as='controlm',\n", " when=Folder.When(week_days=['SUN']),\n", " active_retention_policy=Folder.ActiveRetentionPolicy.KeepAll,\n", " days_keep_active='41',\n", " confirm=True,\n", " created_by='user',\n", " description='FolderSample with lot of properties set',\n", " priority=Folder.Priority.High,\n", " rerun=Folder.Rerun(every='2'),\n", " rerun_limit=Folder.RerunLimit(times='3'),\n", " time_zone='HAW',\n", " variables=[{'var1': 'val'}, {'var2': 'val2'}]\n", " )\n", "\n", "folder.sub_folder_list.append(\n", " SubFolder('MySubFolder1', job_list=[\n", " # this job will run as dummy, the command will not be executed\n", " JobCommand('MyFirstJob', command='ls', run_as_dummy=True),\n", " # This job is marked as 'confirm', it will not run until user confirms\n", " JobCommand('OtherJob', command='ls', confirm=True),\n", " ],\n", " if_list=[\n", " IfCompletionStatus('goodScenario', completion_status='OK', on_list=[\n", " ActionMail('sendMail', message='All jobs ran successfully',\n", " to='team@comp.com', subject='Jobs notification')\n", " ]),\n", "\n", " IfCompletionStatus('badScenario', completion_status='NOK', on_list=[\n", " ActionRun('runCorrectiveJob',\n", " folder='REMEDY_FOLDER', job='RemedyJob')\n", " ])\n", "\n", " ],\n", " notify_list=[\n", " NotifyNotOK(\n", " 'alertIfNOK', destination=Notify.Destination.Alerts, message='Jobs not ok'),\n", " NotifyDoesNotEnd('alertIfJobIsStuck', by='1200',\n", " destination=Notify.Destination.Alerts, message='Jobs didnt end'),\n", " ]\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## When\n", "\n", "[AutomationAPI Documentation](https://documents.bmc.com/supportu/API/Monthly/en-US/Documentation/API_CodeRef_JobProperties.htm?days#When)\n", "\n", "Enables you to define scheduling parameters for Jobs, Folders and SubFolders, including the option of using calendars. If When is used in a Folder or SubFolder, those parameters apply to all Jobs in the Folder or Subfolder.\n", "\n", "Note: Several parameters under the When parameter enable you to reference previously defined calendars.\n", "\n", "When working in a Control-M Workbench environment, jobs will not wait for time constants and will run in an ad-hoc manner. Once deployed to a Control-M instance, all time constraints will be obeyed. \n", "\n", "**Parameters:**\n", "\n", "- **week_days**\n", "\n", "*Note: Not supported in SubFolder*\n", "\n", "One or more of the following: \"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"\n", "\n", "For all days of the week, use \"ALL\" (the default value).\n", "In addition, you can specify a specific day in a specific week of the month using a value with the following format: DdayWn\n", "\n", "For example, DMONW2 means Monday of the 2nd week of the month. Valid values for n are 1-6.\n", "\n", "- **months**\n", "\n", "*Note: Not supported in SubFolder*\n", "\n", "One or more of the following:\n", "\n", "\"JAN\", \"FEB\", \"MAR\", \"APR\",\"MAY\",\"JUN\", \"JUL\", \"AUG\",\n", "\n", "\"SEP\", \"OCT\", \"NOV\", \"DEC\"\n", "\n", "For all months of the year, use \"ALL\" (the default value).\n", "\n", "- **month_days**\n", "\n", "*Note: Not supported in SubFolder*\n", "\n", "One or more days in the range of 1 to 31\n", "\n", "For all days of the month, use \"ALL\" (the default value).\n", "\n", "- **from_time**\n", "\n", "FromTime specifies that a job will not start before this time\n", "\n", "Format: HHMM\n", "\n", "- **to_time**\n", "\n", "ToTime specifies that a job will not start after this time\n", "\n", "Format: HHMM\n", "\n", "To allow the job to be submitted even after its original scheduling date (if it was not submitted on the original date), specify a value of \">\".\n", "\n", "- **schedule**\n", "\n", "*Note: Not supported in SubFolder*\n", "\n", "One of the following options:\n", "\n", " - \"Everyday\" - scheduling is applied every day, provided that the running criteria are met\n", " - \"Never\" - no scheduling is defined, and the job must be ordered manually\n", "\n", "- **specific_dates**\n", "\n", "*Note: Not supported in SubFolder*\n", "\n", "Specific dates for running jobs.\n", "\n", "For each date, use the format \"MM/DD\" (enclosed in quotes). Separate multiple dates with commas.\n", "\n", "Note: The SpecificDates option cannot be used in combination with options WeekDays, Months, or MonthDays.\n", "However, since the default for these options is \"ALL\", you must specify these options with a value of \"NONE\"." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "when = Job.When(\n", " schedule='Never',\n", " months=['JAN', 'OCT', 'DEC'],\n", " month_days=['22', '1', '11'],\n", " week_days=['MON', 'TUE'],\n", " from_time='1500',\n", " to_time='1800'\n", ")\n", "\n", "# example with specific dates\n", "when = Job.When(\n", " week_days=['NONE'],\n", " months=['NONE'],\n", " month_days=['NONE'],\n", " specific_dates=['03/10', '03/01']\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## If\n", "\n", "[AutomationAPI Documentation](https://documents.bmc.com/supportu/API/Monthly/en-US/Documentation/API_CodeRef_JobProperties.htm?properties#If)\n", "\n", "If statements trigger one or more actions when job-related criteria are fulfilled (for example, the job ended with a specific status or the job failed several times)." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfCompletionStatus\n", "\n", "Triggers actions based on job completion status. In this example, if the job runs unsuccessfully, it sends an email and runs another job. You can set this property for a Job, Folder, or SubFolder" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='echo Hello')\n", "job.if_list.append(\n", " IfCompletionStatus('action_if_failure',\n", " completion_status='NOTOK',\n", " on_list=[\n", " ActionMail(\n", " 'mailToTeam', message='Job %%JOBNAME failed', to='myteam@mail.com'),\n", " ActionRun('runcorrectiveJob',\n", " folder='FolderName', job='JobName')\n", " ]\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfNumberOfReruns\n", "\n", "Trigger an action based on number of job reruns. You can set this property for a Job, Folder, or SubFolder" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfNumberOfReruns('actionByNumberOfReruns',\n", " number_of_reruns='>=4',\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')])\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfNumberOfFailures\n", "\n", "Triggers an action based on number of job failures. You can set this property for a Job, Folder, or SubFolder" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfNumberOfFailures('ActionByNumberOfFailures',\n", " number_of_failures='1',\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')])\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfJobNotSubmitted\n", "\n", "Triggers an action based on whether the job is not submitted" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfJobNotSubmitted('ActionByJobNotSubmitted',\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')])\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfJobOutputNotFound\n", "\n", "Triggers an action based on whether the job output is not found" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfJobOutputNotFound('ActionByOutputNotFound',\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')])\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfNumberOfExecutions\n", "\n", "Triggers an action based on number of job executions. You can set this property for a Job, Folder, or SubFolder" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfNumberOfExecutions('ActionByNumberExecutions',\n", " number_of_executions='>=5',\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')])\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfOutput\n", "\n", "Triggers an action based on whether a specified string is found within the job output. You can set this property for a Job, Folder, or SubFolde" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfOutput('OutputFound',\n", " code='myfile.sh',\n", " statement='ls -l',\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')])\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### IfVariableValue\n", "\n", "*Note: This feature requires Control-M/Enterprise Manager version 9.0.21*\n", "Triggers an action based on whether a logical condition defined for a variable value is true" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"Type\": \"Job:Command\",\n", " \"VariableValue\": {\n", " \"Type\": \"If:VariableValue\",\n", " \"RunJob\": {\n", " \"Type\": \"Action:Run\",\n", " \"Folder\": \"Folder1\",\n", " \"Job\": \"Job1\"\n", " },\n", " \"RunJob1\": {\n", " \"Type\": \"Action:Run\",\n", " \"Folder\": \"Folder1\",\n", " \"Job\": \"Job1\"\n", " },\n", " \"VariableName\": \"IpAddress\",\n", " \"VariableValue\": \"1\",\n", " \"Operator\": \"EndWith\"\n", " },\n", " \"Command\": \"echo Hello\"\n", "}\n" ] } ], "source": [ "job = JobCommand('Job2', command='echo Hello')\n", "job.if_list.append(\n", " IfVariableValue('VariableValue',\n", " variable_name='IpAddress',\n", " variable_value='1',\n", " operator=IfVariableValue.Operator.EndWith,\n", " on_list=[ActionRun('RunJob', folder='Folder1', job='Job1')],\n", " do_list=[ActionRun('RunJob1', folder='Folder1', job='Job1')])\n", ")\n", "\n", "print(job.dumps_aapi(indent=2))" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## If Actions\n", "\n", "[AutomationAPI Documentation](https://documents.bmc.com/supportu/API/Monthly/en-US/Documentation/API_CodeRef_JobProperties.htm?days#IfActions)\n", "\n", "Actions that can be triggered in response to an *If* statement that is fulfilled" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionMail\n", "\n", "Action that sends an e-mail\n", "\n", "Arguments:\n", "\n", "- **urgency** : level of urgency of the message. Default: Regular\n", "- **subject** : subject line for the message\n", "- **message** : the message text\n", "- **to** : List of recipients separated by semicolon (;)\n", "- **cc** : List of recipients who receive a copy of the message separated by semicolon (;)\n", "- **attach_output** : whether to include the job output as an email attachement\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "action = ActionMail(\n", " 'mailToTeam',\n", " urgency=ActionMail.Urgency.Urgent,\n", " subject='Completion Mail',\n", " message='%%JOBNAME just completed',\n", " to='team@comp.com',\n", " cc='other@comp.com',\n", " attach_output=True\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionRerun\n", "\n", "Action that reruns the job" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "action = ActionRerun('rerunAction')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionSet\n", "\n", "Action that sets a variable" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "action = ActionSet('SetVariable', variable='var1', value='1')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionSetToOk\n", "\n", "Action that sets the job status to OK" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "action = ActionSetToOK('SetToOk')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionSetToNotOK\n", "\n", "Action that sets the job status to NotOK" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "action = ActionSetToNotOK('SetToNotOk')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionStopCyclicRun\n", "\n", "Action that disables the cyclic attribute of the job" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "action = ActionStopCyclicRun('SetToOk')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionRun\n", "\n", "Action that runs another job" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "action = ActionRun('CorrectiveJob',\n", " folder='FolderName',\n", " job='JobName',\n", " controlm_server='ctmserver',\n", " date='010218',\n", " variables=[{'cvar1': 'val1'}, {'cvar2': 'val2'}],\n", " run_as_independent_flow=True\n", " )\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionNotify\n", "\n", "Action that sends a notification" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "action = ActionNotify('NotifyAction',\n", " message='job just ran',\n", " destination=ActionNotify.Destination.JobLog,\n", " urgency=ActionNotify.Urgency.VeryUrgent)\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionRemedy\n", "\n", "Action that creates a Remedy ticket" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "action = ActionRemedy('RemedyTicket',\n", " summary='CONTROL-M job %%JOBNAME on node %%NODEID return code %%COMPSTAT',\n", " message='CONTROL-M job %%JOBNAME run %%RUNCOUNT ended on node %%NODEID return code %%COMPSTAT Application: %%APPLIC',\n", " urgency=ActionRemedy.Urgency.Low\n", " )\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ActionOutput\n", "\n", "Action that copies the output to a specified destination" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "action = ActionOutput(\n", " 'CopyOutput', operation=ActionOutput.Operation.Copy,\n", " destination='/home/copyHere')\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Notify\n", "\n", "[AutomationAPI Documentaion](https://docs.bmc.com/docs/automation-api/monthly/job-properties-993192276.html#JobProperties-Notification)\n", "\n", "Create a notification for certain scenarios before, during and after job execution. You can set notifications for a Job, Folder, or SubFolder" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyOk\n", "\n", "Notify if jobs is executed without errors" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyOK('Notify1',\n", " message='Job OK',\n", " destination=Notify.Destination.JobLog)\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyNotOk\n", "\n", "Notify if the job is executed with errors" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyNotOK('Notify1',\n", " message='Job NOT OK',\n", " destination=Notify.Destination.Alerts)\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyDoesNotStart\n", "\n", "Notify if the job has not started" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyDoesNotStart('Notify1',\n", " message='Job did not start',\n", " by='1510',\n", " destination=Notify.Destination.Console)\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyExecutionTime\n", "\n", "Notify if the execution time is different than expected" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyExecutionTime('Notify1',\n", " message=\"Job didn't complete in less than 3 minutes\",\n", " destination=Notify.Destination.JobLog,\n", " criteria=NotifyExecutionTime.Criteria.LessThan,\n", " value='3'\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyDoesNotEnd\n", "\n", "Notify if the job does not end by the specified time" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyDoesNotEnd('Notify1',\n", " message=\"Job didn't by 12h20\",\n", " destination=Notify.Destination.JobLog,\n", " by='1220'\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyReRun\n", "\n", "Notify if the job reruns" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyRerun('Notify1',\n", " message=\"Job reran\",\n", " destination=Notify.Destination.JobLog\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### NotifyLateCyclicSubmit\n", "\n", "*Note: This feature requires Control-M/Enterprise Manager version 9.0.21*\n", "\n", "Notify if the second or subsequent cyclic submission is late by a specified number of minutes" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls -l')\n", "job.notify_list.append(\n", " NotifyLateCyclicSubmit('Notify1',\n", " message=\"Cyclic job did not submit on time\",\n", " destination=Notify.Destination.JobLog,\n", " by='10' # Job cyclic is late by 10 minutes\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Resources\n", "\n", "[AutomationAPI Documentation](https://documents.bmc.com/supportu/API/Monthly/en-US/Documentation/API_CodeRef_JobProperties.htm?days#Resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ResourcePool\n", "\n", "Sets a pool (previously known as quantitative resources or semaphore) on a job, to control access to a resource that is concurrently shared by other jobs" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "folder = Folder('ResourceSample',\n", " job_list=[\n", " JobCommand('job1', command='ls', resource_list=[\n", " ResourcePool('semaphore1', quantity='3')\n", " ]\n", " )\n", " ]\n", " )" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### ResourceLock\n", "\n", "Sets a lock (previously known as a control resource or mutex) as shared or exclusive. If the resource is shared, other jobs can use the resource concurrently. If set to exclusive, the job has to wait until the resource is available before it can run. You can set a lock on a Job, Folder, or SubFolder" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "folder = Folder('ResourceSample',\n", " job_list=[\n", " JobCommand('job1', command='ls', resource_list=[\n", " ResourceLock(\n", " 'lock1', lock_type=ResourceLock.LockType.Exclusive)\n", " ]\n", " )\n", " ]\n", " )\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Rerun\n", "\n", "Allows to define cyclic jobs or folders\n", "\n", "Arguments: \n", "\n", "- **every** : The frequency at which to run the cyclic job or folder, expressed as a whole number of the specified time unit\n", "- **units** : One of the following: \"Minutes\" \"Hours\" or \"Days\". The default is \"Minutes\"\n", "- **from_** : Start - next run time is calculated an N Units from the start time of the current run, End - next run time is calculated as N Units from the end time of current run, Target - run starts every N units\n", "- **times** : Number of cycles to run (as a string). To run forever, define \"0\"" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "job = JobCommand('Job1', command='ls', rerun=Job.Rerun(\n", " every='4', \n", " from_=Job.Rerun.From.End, \n", " times='3',\n", " units=Job.Rerun.Units.Days))" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Variables\n", "\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Events\n", "Events can be generated by Control-M or can trigger jobs. Events are defined by a name and a date.\n", "\n", "Here is a list of the various capabilities of event usages:\n", "\n", " A job can wait for events before running, add events after running, or delete events after running. See [WaitForEvents](#WaitForEvents), [AddEvents](#addevents), and [DeleteEvents](#deleteevents)\n", "\n", "You can set events for a Job, Folder, or SubFolder.
\n", "For \"Date\", you can use the following values:\n", "\n", "|Date Type | Description | \n", "| --------------- | --------------- |\n", "| AnyDate | Any scheduled date | \n", "| OrderDate | Control-M scheduled date.If you do not specify a Date value, this is the default. | \n", "| PreviousOrderDate | Previous Control-M scheduled date |\n", "| NextOrderDate | Next Control-M scheduled date | \n", "| MMDD | Specific date Example: \"0511\" | \n", "\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### WaitForEvents\n", "The following example shows how to define events that the job must wait for before running:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "waitForEventList = WaitForEvents([Event(event=\"e1\"), Event(event=\"e2\"), Event(event=\"e3\", date=Event.Date.AnyDate)])\n", "job = JobCommand('Job1', command='echo Hello')\n", "job.event_list.append(waitForEventList)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### AddEvents\n", "The following example shows how to specify events for the job to add after running:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "addEventListObject = AddEvents([EventOutAdd(event=\"e4\",date=Event.Date.NoDate)])\n", "job = JobCommand('Job1', command='echo Hello')\n", "job.event_list.append(addEventListObject)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### DeleteEvents\n", "The following example shows how to specify events for the job to remove after running:" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "deleteEventListObject = DeleteEvents([EventOutDelete(event=\"e5\",date=Event.Date.NextOrderDate)])\n", "job = JobCommand('Job1', command='echo Hello')\n", "job.event_list.append(deleteEventListObject)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.4 ('venv': venv)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.9" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "e36608863334e111ac1975278d851976534d4d97e80edd449207481e04c86242" } } }, "nbformat": 4, "nbformat_minor": 2 }