NAV 2017 “Task Scheduler”
In this post i will write about “NAV 2017 Task Scheduler”, NAV 2017 Task Scheduler is an evolution of Job Queue Technology (ex Process Queue, Microsoft returned to old name for name for Job Queue..); Microsoft has reviewed\improved\extended the old Job Queue Technology and now Task Sheduler is a great new feature ready for “Complex Scheduling” useful in various scenarios.
MSDN Definition: “The task scheduler enables you to control when certain operations or processes (in other words tasks) are run. Basically, a task is a codeunit or report that is scheduled to run at a specific data and time. Tasks run in a background session between the Microsoft Dynamics NAV Server instance and database. Behind the scenes, the task scheduler is used by the job queue to process job queue entries that are created and managed from the clients.”
How “New Task Scheduler System” works
Now we have a new option in NST: “Task Scheduler enabled” option; when a task is executed, the task is not visible in sessions list (is a background session).
“Task Scheduler enabled” option says to NST to start a background session for each task that needs to be executed at scheduled time. After the execution of task is completed, the background session is closed (no more phantom\pending sessions to kill by SQL jobs !)
Another useful option on NST permit to define how many simultaneous tasks can be executed by NST at the same time (parallel execution on NST). Killing a session will not stop all other tasks that need to be executed (..a different pipeline for each task execution)
“Task Scheduler Technology” Objects involved
- Table 2000000175 Scheduled Task (Show list of scheduled task)
- Table 2000000111 Session Event (Show list of active background sessions started for each running task)
“Job queue” Codeunits
Below Some Details of New Task Scheduler Feature
C/AL Code and Task Scheduler
In C/AL code, you create and manage tasks by using the C/AL functions that are available for the TASKSCHEDULER data type.
Task Scheduler Data Type
The TaskScheduler data type is a complex data type for creating and managing tasks in the task scheduler, which runs codeunits at scheduled times.
“ALL” Task Scheduler Functions
|CREATETASK||Adds a task to run a codeunit at a specified date and time.|
|SETTASKASREADY||Sets a task to the Ready state. A task cannot run until it is Ready.|
|TASKEXISTS||Checks whether a specific task exists.|
|CANCELTASK||Cancels a scheduled task.|
“How “ Task Scheduler Works
To set up a task, you create a codeunit that contains the logic that you want to run at a scheduled time. Optionally, you can create a second codeunit that contains the logic to handle the task if an error occurs for any reason. This coduenit is referred to as a failure codeunit. Once you have the codeunits, you can add C/AL code to the application that calls the CREATETASK function to schedule a task to run the codeunits. The CREATETASK function can also specify the earliest date to run the task, and whether the task is in the ready state.
Task Scheduling “Flow”
Here is an overview of the process that a task goes through:
- After you add a task, the task is recorded in table 2000000175 Scheduled Task of the database.
- If the task is in the ready state, when the scheduled time occurs, a new background session is started and the task codeunit is run.
You can view the session in the table 2000000111 Session Event.
If an error occurs, the following happens:
- If a failure codeunit is not specified, then the retry flow is initiated.
- If a failure codeunit has been specified, the error is passed in a call to the failure codeunit, and the failure codeunit is run.
- If the failure codeunit does not handle the error or fails itself, then the retry flow is initiated.
Error Conditions and Retry Process
A task can fail under the following conditions:
- The company cannot be opened.
- An SQL connection or transient error occurred with the database.
- The Microsoft Dynamics NAV Server instance restarted while the task was being run. When an error occurs, unless the task is interrupted by the failure codeunit, the Microsoft Dynamics NAV Server instance will rerun the task according to the following flow:
- You can view these errors in the event log of the computer that is running the Microsoft Dynamics NAV Server instance.
- Two minutes after the first failure
- Four minutes after the second failure
- Fifteen minutes after the third failure and subsequent failures.
About Task Sessions and Permissions
The task runs in a background session, which means that there is no user interface. The behavior is similar to that of the STARTSESSION function, where any dialog boxes that would normally appear are suppressed. For more information about specific dialog boxes, see STARTSESSION Function (Sessions).
The session runs by using the same user/credentials that are used when calling C/AL code. The user must have appropriate permissions to the codeunit and any other objects that are associated with the operation of the codeunit.
Create Task Function
Adds a task to run a codeunit at a specific time.
[Task =: ]CREATETASK(CodeunitId, FailureCodeunitId[, IsReady][, Company][, NotBefore][, RecordID])
The following example schedules a task to run the Job Queue Dispatcher and uses codeunit Job Queue Error Handler as the failure codeunit. The code requires that you create the following C/AL variable.
|JobQueueEntry||Record||Job Queue Entry|
TASKSCHEDULER.CREATETASK(CODEUNIT::”Job Queue Dispatcher”, CODEUNIT::”Job Queue Error Handler”, TRUE, COMPANYNAME, CURRENTDATETIME + 1000 + RANDOM(3000), JobQueueEntry.RECORDID);
“JOB QUEUE” IMPROVEMENTS
SET STATUS TO “ERROR” FEATURE
NST Reporting Parameters (nice for SAVEAS function and for reporting scheduling also)
Sample of Report Scheduling
My final considerations: New Task Scheduler is Great feature ! ….now Task Scheduler is a real scheduling application like windows task scheduler or Unix Crontab etc… a great step beyond!!
Have a nice task scheduling !!
12 thoughts on “NAV 2017 “Task Scheduler””
Pingback: NAV 2017 WHAT’S NEW – ALL MY POSTS | Roberto Stefanetti NAV Blog
With the old NAS we could use a category filter to split the different tasks per job queue (service).
Here fore we used one job queue for all daily processes as shown below, this process runs all processes that are created daily such as posting purchase and sales orders via job queue with category DAY.
The other job queue is setup for the night processing of recurring job queue entries with category NIGHT, such as ‘cost price adjustment’ and ‘posting inventory values to GL’.
• Each job queue process has its own service running on the server and runs only job queue entries with corresponding job queue category. This is done so because the day process can sometimes stop because of errors and in this case the night process is still handling the tasks that are critical for reporting numbers the next day.
• It’s important that the DAY job queue only handles job queue entries with category DAY and must not handle the tasks of the NIGHT job queue (when not using the category’s to split the process ‘posting inventory values to GL’ was started by the DAY job queue in parallel with ‘cost price adjustment’ and they blocked each other). This is achieved by the job queue card definition what defines which service runs the job queue and what the job queue category filter is to select entries to process.
• The NIGHT job queue must handle its own processes in a serial (and not parallel) manner.
How can we achieve this in NAV2017 when running the new task scheduler? We can setup that the task scheduler process for running only 1 process at a time in order to prevent parallel processing but how can we start each task scheduler process for their specific job queue category? What we see is that a task scheduler process is always handling all job queue entries, when the first process is still running ‘cost price adjustment’ and the starting time of the second process ‘posting inventory values to GL’ is reached the second process picks this one for processing. It looks like job queue category’s has no function anymore?
Hi I have similar problem – I need to run different tasks using different user privileges (automatic saving files to server, where access rights could not be set for Network services). How is going NAV to decide which service will run which task? And if it selects incorrect service and fails while processing the task, I suppose it will persist on trying to run it again on the same service instead of selecting another service which could process it?
With job queue category it was easily possible.
If you find some workaround I would be grateful…
in the service tier for the task scheduler your can setup the no. of parallel background sessions. Per category code only one background session is used. So if you use the same category the processing is serial. if you set the no of sessions to 1 its always serial.
But how to always run Jobs after each other (serial) and in the same order?
See my (MGN) comment at https://forum.mibuso.com/discussion/69228/job-queue-category-in-nav-2017
Pingback: “How to” print reports to PDF and send email | Roberto Stefanetti NAV Blog
Pingback: NAV 2017 not documented options for “Credential Type” « Roberto Stefanetti NAV Blog
Pingback: NAV 2017 not documented options for “Credential Type” - Microsoft Dynamics NAV Community
Pingback: NAV 2017 not documented options for “Credential Type” - Roberto Stefanetti's NAV Blog - Dynamics NAV Users - DUG
Pingback: How to restart a job in “Error” or “Frozen Completed” status | Roberto Stefanetti NAV Blog
Pingback: How to restart a job in “Error” or “Frozen Completed” status - Roberto Stefanetti's NAV Blog - Dynamics NAV Users - DUG
That is very interеsting, Yⲟu’re a vеry ptofessional blogger.
Ӏ’ve joined your rss feed and stay up fߋr іn search off extra of үour fantastric post.
Additionally, І havе hared your site in mү socisl networks
Comments are closed.