Taskman Internals

= Taskman components =

Routines
 * %ZTLOAD (API to create a task)
 * Manager
 * Sub-manager
 * The menu options to use to manipulate Taskman

Globals
 * %ZTSCH (the tasks "index" plus control structures for taskman... not a Fileman file)
 * %ZTSK (Tasks Fileman file)

^%ZTSK Structure
^%ZTSK contains the actual task.

^%ZTSK(-1) contains the most recently assigned task.

.1 node: Current Status
 * 1 -> Scheduled by %ZTLOAD
 * 2 -> Not on any list
 * L -> Rejected
 * 3 -> In Job List
 * A -> In IO List
 * 4 -> Not on any index, but prepping
 * 5 -> On task list (i.e. running)
 * 6 -> Succeeded (NB: may not see this if task gets deleted immediately)

.2 node: IO

.3 node: Variables to use in the task

^%ZTSCH Structure
^%ZTSCH has indexes on the task file. It decides when a task will be run.

^%ZTSCH(seconds, task number) is the index of what to do when. The number of seconds is since the $H epoch.

Once a task is ready to run, it kills off the entry in (sec,task#) and puts it in another index ("JOB",sec,task#) or in ("IO",sec,task#) for tasks waiting for a device.

Submanagers watch ^%ZTSCH("IO") and ("JOB"). Once they find something, they kill it off there and put it in ("TASK").

("SUB") contains the list of available submanagers.

Submanagers run the job directly (no job command). The manager keeps looking for free submanagers and adds submanagers

= Taskman Monitor Counters =

Task List

 * ("SUB") (# number of subs available)
 * ("TASK") -> Number of running tasks.

To obtain the sub, do the following: N ZTPAIR D SUBCHK^%ZTMS5(0) Q ^%ZTSCH("SUB",ZTPAIR)

Job List
("JOB") -> Almost always empty. If increasing, it's a warning sign. Increase triggers submanager launches.

IO List
For specific devices (e.g. Printers). Submanager will process IO list sequentially and then go back to job list.

Host files do not go to IO list; they stay in the Job List

If you can't get a device, taskman reschedules the job for the future.

Schedule List
^%ZSTCH($H in seconds,task number in ^%ZTSK) -- Tasks scheduled to start in the future.

$H has to be converted to seconds b/c $H itself collates alphabetically. Cf. `$$SEC^XLFDT`

It's normal to have some late, because they have to be late in order to run.

Status List
%ZTSCH("STATUS") tells what Taskman is doing. Time stamp shouldn't be more than 10-15 seconds old. You can have multiple managers running. It's updated by manager. Has Job # as subscript.

^%ZTSCH("RUN") tells you when it was last updated.

= Booting = To start clean, ^ZTMB. To re-start RESTART^ZTMB.

= Wait State = Artificial state intended to help programmers and system managers. No longer take from the Schedule List and put on the Job List.

= Taskman Routines =
 * ZTM* Manager
 * ZTMS* Submanagers. Submanager started by manager using J ^%ZTMS
 * XTUM*
 * XUTMTZ Troubleshooting kit
 * XUTMD Delete
 * XUTMDQ Dequeue
 * XUTMTP Print
 * XUTMR Reschedule
 * XUTMU User option
 * XUTMT Toolkit

= Taskman Statuses =

Start
Initial State when you start via ^ZTMB

Start-up Hang
Wait time after starting to give the operating system and peripherals (esp. printers) time to boot. Controlled by Field Manager Startup Delay (#32) in 14.7. Today, this pretty much doesn't apply; you should set it to 1 second.

Pause
Controlled by INHIBIT LOGONS? (#1) in 14.5 and REQUIRED VOLUME SET? (#4) In 14.5.

Run
The desired state when everything is fine.

Taskman Job Limit Reached
Won't start any more submanagers. Intent is to throttle based on Taskman Job Limit.

Wait
Does two things: Manager cannot start submanagers AND Manager cannot move items from Schedule List to "IO" and "JOB". Does not affect currently running jobs. When placing into wait via menu option XUTM WAIT, you can ask for the submanagers to halt after they finishing with their current jobs. Mainly for debugging code.

To remove wait, option XUTM RUN.

To remove wait manually while debugging: for manager:

K ^%ZTSCH("WAIT","MGR")

To remove submanager from wait,

K ^%ZTSCH("STOP","SUB",box-vol)

When the manager is removed from wait, it moves the tasks from the Schedule List to "IO" and "JOB"; it changes the .1 node on the task in ^%ZTSK from Status 1 to Status 3 or A ^ $H status change date and fills the the .2 node: Volume/UCI.

= Detailed workflow = ^ZTMB stands for Boot. Boot jobs off ^ZTM0.

^ZTM0 does initialization then goes to ZTM.

^ZTM0 initialization:
 * ET
 * Set status to start-up
 * Check to see if ^%ZTSCH is locked
 * Kill ^%ZTSCH("DEV")
 * Kill ^%ZTSCH("DEVOPEN")
 * Kill ^%ZTSCH("LOAD")
 * Kill ^%ZTSCH("LOADA")
 * Kill ^%ZTSCH("STATUS")
 * Kill ^%ZTSCH("STOP")
 * Kill ^%ZTSCH("UPDATE")
 * Loop through current tasks and set them to interrupted
 * Set-up (more on that later)
 * Kill ^%ZTSCH("TASK")
 * Kill ^%ZTSCH("SUB")
 * Set Status to Hang
 * Start-up Hang
 * Startup jobs
 * Goto ZTM