AX1765
Run another Scheduler job from within a Scheduler job
Scheduler jobs have two ways to run another Scheduler job:
-
Raise Event task: This task uses an event handler name to trigger one or more Scheduler jobs for execution. The jobs triggered by the event handler are run independently from the job containing the Raise Event task.
-
Run Scheduler Job task: This task runs a specified Scheduler job as a subordinate job within the current "parent" job. Essentially, the tasks in the target job are run within the parent job, which means that other tasks in the parent job can reference the results of those tasks.
The decision of which task to use depends on several factors, but the most important is whether the Scheduler jobs are independent or dependent. If the first job is dependent on the execution of the second job, then you must use the Run Scheduler Job task. When the Raise Event task is used, the triggered jobs are run independently.
The following chart details some comparison points between the two tasks:
Comparison | Raise Event | Run Scheduler Job |
---|---|---|
Can pass variables to target job |
Yes |
Yes |
Can execute target job as requester or owner |
Yes |
No |
Can wait for target job to complete before continuing |
No |
Yes |
Can use results of target job in subsequent tasks |
No |
Yes |
Using the Raise Event task
The Scheduler Raise Event task is typically used when you need to trigger another job for execution once the current job is complete. The Scheduler job(s) triggered by the event handler are added to the schedule and then executed independently from the current job. For example, you might place the Raise Event task at the end of the task list, so that all tasks in the current job must complete successfully before the Raise Event task is run.
Because the jobs triggered by the event handler are run independently, you cannot perform additional tasks in the current job that depend on the results of the triggered jobs. The current job will not wait for the triggered jobs to be run.
Event handlers can be configured to run a job as either the job owner or as the requester (meaning the user that triggered the event). This allows some additional flexibility in how the triggered jobs are run. For example, you may want to trigger a job that needs to be run using administrator permissions. As long as the event handler is configured to run as job owner (and the owner is an administrator), then that triggered job will always have the necessary permissions, regardless of the user who is running the job with the Raise Event task.
Using the Run Scheduler Job task
The Run Scheduler Job task is typically used when you need to run another job and then perform additional tasks once that job is complete. Because the target job is run as a subordinate job within the "parent" job, the parent job can wait for the "child" job to complete before it continues processing tasks. Later tasks in the parent job can reference the results of the completed child job, such as querying data saved from the child job, processing plan files created by the child job, and so on.
Keep in mind that it is not possible to stop processing tasks in the parent job based on the general success or failure of the child job. Although Scheduler jobs automatically stop processing if a task fails, the task in this case is just the Run Scheduler Job task. As long as the child job can be successfully added to the Scheduler queue for processing, the Run Scheduler Job task will report success. If needed, you can use the option Process task only if the value of this expression is true to detect whether a subsequent task in the parent job should be processed. For example, if you know that the child job saves a particular value to the database, you can check for the existence of that value to determine whether to process a task. For more information on using this option, see Conditionally processing tasks in a job.
The child job is run using the same user permissions as the parent job. The user running the parent job must have the appropriate permissions to complete all tasks in both the parent job and the child job.
Chaining multiple Scheduler jobs
You can "chain" multiple Scheduler jobs together using either approach. For example, you may have three Scheduler jobs that you want to run, in a particular order.
You can place multiple Run Scheduler Job tasks in a parent job, where each task triggers a separate job. Because these tasks run as subordinate jobs, and the parent job can wait for each child job to complete, it is easy to run the jobs in order. However, if you want to stop processing the jobs if one fails, there is no built-in way to do that (as discussed in the previous section). You would need to set up the Run Scheduler Job tasks to run or not based on a condition, where the condition tests some result from the previous job.
To chain jobs using Raise Event, the last task in each job can be a Raise Event task. Each job will perform its tasks and then trigger the next job in the chain. When using this approach, the chain automatically stops if failure occurs, because if a task in the job fails then the job stops and will not proceed to the Raise Event task. The disadvantage of this approach is that the jobs cannot also be run separately, unless you manually disable the Raise Event tasks or configure the Raise Event tasks to not run based on a condition.