Task scheduler
Hi,
I've a list of running scheduled task in task manger and would to crate a tasks to monitor if any of my tasks has stopped running, is there a function to check tasks status?
Thanks
Comments
Hello @Nezla,
The %SYS.Task class has the task details which includes the status of the task. The "Suspended" column has value if incase the task is errored out while running ("Suspend Leave" ) or the task is suspended ("Suspend Reschedule"). Based on this column you can find out the suspended /errored task. Use the below query for the TaskName and additional details.
selectName,Status,TaskClass,Suspended from %SYS.TaskThanks Ashok
Would this SQL be more accurate?
select Name,Status,TaskClass,Suspended from %SYS.Task <> 1
If not, why?
Sorry left out the variable 'Status'
select Name,Status,TaskClass,Suspended from %SYS.Task where Status <> 1
Hello @Phillip Wu
The "status" is set to 1 for tasks that are either currently suspended ("Suspended Reschedule") or encounter an error during execution. If the "Suspend task on error?" option is set to "no" when scheduling the task, the error message is stored in the status column. However, the task status is not suspended.
From documentation
If the job is currently running (JobRunning) Status will be -1
If there was an untrapped error (JobUntrappedError) Status will be -2
If there was an error before execution (JobSetupError) Status will be -3
If the task timed out trying to job (JobTimeout) Status will be -4
If there was an error after execution (JobPostProcessError) Status will be -5
The text of the status code will be in the property Error.
SQL Query
selectName,displaystatus,Error,Suspended,%IDfrom %SYS.Task Where Suspended=1or Suspended=2Query method
set tResult = ##class(%SYS.Task).TaskListFilterFunc("Suspend")
do tResult.%Display()