Summary
A Job Queue allow you to set a limit on the maximum number of concurrent jobs that can run within the Queue.
In some cases it may be useful to programmatically change this limit. For example, you may want to set a limit during a certain portion of your processing cycle, but remove the limit during other times.
This article explains how to use the adTempus API to make the changes.
Procedure
You will first create a Script Library that contains supporting code.You will then create jobs that runs the script code.
Create the Script Library
1. In the adTempus Console, expand the Scripts folder, then right-click Script Libraries and choose New Script Library....
2. In the Script Library Properties window:
a. Name the library "QueueLimits"
b. Select "VB.NET" for the Language
c. Erase the default script code and paste in the following code:
Imports System.Collections.Generic Imports ArcanaDevelopment.adTempus.Client Public Module QueueLimits 'Sets the concurrent job limit for the specified queue. 'Call with jobLimit=0 for no limit 'See www.arcanadev.com/support/kb/K00000380.aspx for more information Public Sub SetQueueLimit(ByVal queueName As String, ByVal jobLimit As Integer ) Dim session As Scheduler Dim queue As JobQueue 'create a new session to the local adTempus instance session = CreateSession() queue=GetQueue(session,queueName) If queue Is Nothing Then Throw New System.Exception("The specified Queue could not be found") End If queue.MaxConcurrentJobs=jobLimit queue.Save() adTempus.LogMessage(MessageTypeEnum.Informational,0,"Job limit for Queue """ & queueName & """ set to " & jobLimit) End Sub 'Finds the Queue with the specified name Private Function GetQueue(ByVal session As Scheduler, ByVal queueName As String) As JobQueue Dim queues As ADTObjects queues=session.GetObjectsForClass(ClassIDEnum.CID_JobQueue) For Each queue As JobQueue In queues If String.Compare(queue.Name,queueName,True)=0 Then Return queue End If Next Return Nothing End Function 'Creates a new session with the local adTempus instance. Private Function CreateSession() As Scheduler Dim app As Application app = New Application 'create a new session to the local adTempus instance Return app.Connect("", "") End Function End Module
d. Click OK to save the Script Library.
Set Limits from a Script
Once the Script Library has been created you can call the SetQueueLimit method from an adTempus script to set the conccurrent execution limit for a queue.
To use the code defined in the Script Library:
1. Create a new job, or edit an existing job. Keep in mind the following points:
- The new limit will only affect jobs that are submitted for execution after the change is made. The job that runs the script will not be affected, as it will already be running when the change is made.
- The script uses the adTempus API to update the variables. The API is subject to the same security checks as the adTempus Console. Therefore you must run the job under the User Account of a user who has permission within adTempus to modify the Queue that you are updating.
2. On the Steps page of the Job Properties, add a new step, selecting the "Execute a script" option in the Select Task window.
3. In the Script Execution Task Properties window, select the "Execute a script stored in adTempus" option, then click the Select... button.
4. In the Select Script window, click New... to create a new script.
5. In the Script Properties window, select "VB.NET" as the script Language.
6. Under Included Script Libraries, check the "QueueLimits" library.
7. To set the limit call the SetQueueLimit method using the following syntax:
where QueueName is the name of the queue you want to update and JobLimit is the concurrent job limit. Specify a JobLimit of 0 to remove all limits.
The following script sets the limit for the "Default" queue to 2 concurrent jobs:
Imports System Imports System.Collections Imports ArcanaDevelopment.adTempus.Server Public Class UserScript Inherits ArcanaDevelopment.adTempus.ScriptEngine.UserScriptBase Public Overrides Function Run() As Object SetQueueLimit("Default",2) Return 0 End Function End Class
You can then create another job to reset the limit at the end of the processing cycle, if desired. The following code removes the limit:
Imports System Imports System.Collections Imports ArcanaDevelopment.adTempus.Server Public Class UserScript Inherits ArcanaDevelopment.adTempus.ScriptEngine.UserScriptBase Public Overrides Function Run() As Object SetQueueLimit("Default",0) Return 0 End Function End Class