Running tasks is straightforward process of defining the task, and then launching instances of this task as needed (or scheduling instances to run a number of times). The main advantage of using the SRE2003 task manager, as opposed to a CRON like system utility, is that tasks can be easily launched by daemons, or by web based scripts.
Tasks can be any REXX program, or any executable that can be invoked by a REXX program. When one launches a task, you can provide it an argument (of any length).
The task manager also has resource utilization management capabilities. You can limit the number of tasks that can be running simultaneously, the lifespan of a task, and the frequency with which tasks can be launched. This control can be exercised on families of tasks, whose members can be freely defined.
Although flexible, the task manager has a sequential nature, which means that sometimes tasks will be queued up. Thus, the task manager should not be used to perform real-time resolution of web requests. However, it can be used to produce outputs (say, by a script that uses arguments provided via an html form) that can be delivered to the client at a later date.
For example, this can be as simple as saving a file in a web-accessible location, so that a client can (after a suitably long coffee break) request this output using a predetermined URL (one that points to this web-accessibe location). Alternatively, a client may (after a suitable wait) query an "output manager" script that will return the appropriate output (say, as indexed by the client's username).
To use the task manager, we strongly recommend using the SRE_TASK procedure. Basically, there are several types of actions supported by SRE_TASK:
DEFAULT_MAX_TASK=5 |
The maximum number of simultaneous tasks that can be run simultaneously,
defined across a family of tasks.
Example: DEFAULT_MAX_TASK=6 |
DEFAULT_MAX_LIFESPAN | The default maximum lifespan of a task (in seconds), defined across a family
of tasks.
Example: DEFAULT_MAX_LIFESPAN=1200 |
DEFAULT_MIN_WAIT | The default minimum wait, in seconds, between launching tasks within the
same family. 0 means "no limit". In other words, you can't launch
a task until this many seconds have elapsed since the last task belonging
to this family was launched.
Example: DEFAULT_MIN_WAIT=0 |
ACTION | The action to take. Four actions are recognized:
|
NAME | NAME is a task name or a family name. The task name can also include
a family name.
|
CONTROLS | CONTROLS is optional control information. |
DATA | DATA is used to pass ACTION specific parameters.
|
OWNID | OWNID is strictly optional. It should be the "own id" of the calling procedure (say, as created with the SRE_DMN_OWN procedure). If an OWNID one is not available, SRE_TASK will create one. |
astat will be a status message, or an error
message. Error messages have the form: error error-message |
Action = FAMILY |
This action is used to define families of tasks. Families are used to group tasks together, both as a means of specifying default parameters, and as a means of limiting the number of tasks that can be simultaneously running. It is okay to define a family that will contain only one task.
CONTROLS may contain a comma seperated list of family specific
limits:
Notes on CONTROLS:
With FAMILY, the DATA parameter is ignored.
Notes on the return value:
| ||||||
Action = DEFINE |
DEFINE is used to define a task. Basically,
this is used to associate
a taskname with a file. When defining a taskname, use the .FAMILY to assign the taskname to a family.
CONTROLS can be used to remove an already defined taskname.
DATA must be a fully qualified filename of the REXX program of this task. Note: the return value from the DEFINE action of SRE_TASK is either:
| ||||||
Action=LAUNCH | Launch a task, using NAME to select a task-name (that has
been defined using a prior DEFINE call). Remember to include
a .FAMILY_NAME if needed.
| ||||||
Action = STATS |
Return statistics on defined families, defined tasks,
active tasks, scheduled tasks, and pending tasks.
A simple set of HTML tables is returned. You can send these to a client using SRE_COMMAND('VAR ...') | ||||||
Action = EXIST | Check on whether a family, or a task, has already been defined.
The syntax is:astat=sre_task('EXIST','taskname.familyname')astat will be: To check that a family has been defined, use: astat=sre_task('EXIST','.familyname')That is, have nothing befor the .familyname |
Hint: to schedule a task that begins immediately, you can use two
calls to sre_task. For example:
a REXX procedures that is loaded into macrospace, and called as an external procedureAs with other external procedures, the first line must be a REXX comment (
Tasks will be passed two argument --
When complete, tasks should return with a value of 1. Actually, it doesn't matter what they return -- SRE2003 does not pay attention to what is returned by tasks. However, they should return , rather then exit.
Notes:
Alternatively, to run your task a number of times over a defined period, you can use the SCHEDULE argument when launching a task.