QueueModel#
- class lsst.ts.scriptqueue.QueueModel(domain, log, standardpath, externalpath, next_visit_callback=None, next_visit_canceled_callback=None, queue_callback=None, script_callback=None, min_sal_index=1000, max_sal_index=2147483647, verbose=False)#
Bases:
objectCode to load and configure scripts; implementation for ScriptQueue.
- Parameters:
domain (
salobj.lsst.ts.salobj.Domain) – DDS domain; typicallyScriptQueue.domainlog (
logging.Logger) – Parent logger.standardpath (
str,bytesoros.PathLike) – Path to standard SAL scripts.externalpath (
str,bytesoros.PathLike) – Path to external SAL scripts.next_visit_callback (
coroutine(optional)) – Coroutine to call when a script gets a new group ID. It receives one argument: aScriptInfo. This is separate from script_callback to make it easier to output thenextVisitevent.next_visit_canceled_callback (
coroutine(optional)) – Coroutine to call when a script loses its group ID. It receives one argument: aScriptInfowith group_id not yet cleared.queue_callback (
coroutine(optional)) – Coroutine to call when the queue state changes. It receives no arguments.script_callback (
coroutine(optional)) – Coroutine to call when information about a script changes. It receives one argument: aScriptInfo. This is not called if the only change is to the group ID; seenext_visit_callbackandnext_visit_canceled_callbackfor that.min_sal_index (
int(optional)) – Minimum SAL index for Script SAL componentsmax_sal_index (
int(optional)) – Maximum SAL index for Script SAL componentsverbose (
bool(optional)) – If True then print log messages from scripts to stdout.
- Raises:
ValueError – If
standardpathorexternalpathdoes not exist.
Attributes Summary
SAL index of the current script, or 0 if none.
Get enabled state.
SAL indices of scripts on the history queue.
Get the next available SAL Script index.
SAL indices of scripts on the queue.
Get or set running state.
Methods Summary
add(script_info, location, location_sal_index)Add a script to the queue.
clear_group_id(script_info, command_script)Clear the group ID of the specified script, if appropriate.
close()Shut down the queue, terminate all scripts and free resources.
Find available scripts.
get_queue_index(sal_index)Get queue index of a script on the queue.
get_script_info(sal_index, search_history)Get information about a script.
make_full_path(is_standard, path)Make a full path from path and is_standard and check that it points to a runnable script.
move(sal_index, location, location_sal_index)Move a script within the queue.
Get the next group ID.
pop_script_info(sal_index)Remove and return information about a script on the queue.
requeue(sal_index, seq_num, location, ...)Requeue a script.
set_enable(enabled)Set enabled state.
set_group_id(script_info)Set or clear the group ID for a script.
set_running(run)Set running state.
stop_one_script(script_info)Stop a queued or running script, giving it time to clean up.
stop_scripts(sal_indices, terminate)Stop one or more queued scripts and/or the current script.
Terminate all scripts and return info for the ones terminated.
terminate_one_script(script_info)Terminate a queued or running script.
Attributes Documentation
- current_index#
SAL index of the current script, or 0 if none.
- enabled#
Get enabled state.
True if ScriptQueue is in the enabled state, False otherwise.
- history_indices#
SAL indices of scripts on the history queue.
- next_sal_index#
Get the next available SAL Script index.
- queue_indices#
SAL indices of scripts on the queue.
- running#
Get or set running state.
If set False the queue pauses.
Methods Documentation
- async add(script_info, location, location_sal_index, start_block=False, block_size=0)#
Add a script to the queue.
Launch the script in a new subprocess and wait for the subprocess to start. Start a background task to configure the script when it is ready.
- Parameters:
script_info (
ScriptInfo) – Script info.location (
Location) – Location of script.location_sal_index (
int) – SAL index of script thatlocationis relative to.start_block (
bool, optional) – Start a new block? Default=False.block_size (
int, optional) – How many scripts are part of this block? Default=0
- Raises:
ValueError – If the script does not exist or is not executable.
ValueError – If
locationis not one of the supported enum values.ValueError – If location is relative and a script at
location_sal_indexis not queued.
- Return type:
- async clear_group_id(script_info, command_script)#
Clear the group ID of the specified script, if appropriate.
Clear the group ID of the specified script if the group ID is set or is being set.
- Parameters:
script_info (
ScriptInfo) – Script info.command_script (
bool) – If True then issue the setGroupId command to the script (in the background). The only time you would set this False is if you are about to terminate the script.
- Return type:
- find_available_scripts()#
Find available scripts.
- Returns:
scripts – Paths to standard and external scripts.
- Return type:
Scripts
- get_queue_index(sal_index)#
Get queue index of a script on the queue.
- Parameters:
sal_index (
int) – SAL index of script.- Raises:
ValueError – If the script cannot be found on the queue.
- Return type:
- get_script_info(sal_index, search_history)#
Get information about a script.
Search current script, the queue and history.
- Parameters:
- Returns:
Script info for the requested sal index.
- Return type:
- Raises:
ValueError – If the script cannot be found.
- make_full_path(is_standard, path)#
Make a full path from path and is_standard and check that it points to a runnable script.
- Parameters:
is_standard (
bool) – Is this a standard (True) or external (False) script?path (
str,bytesoros.PathLike) – Path to script, relative to standard or external root dir.
- Returns:
fullpath – The full path to the script.
- Return type:
- Raises:
ValueError – If The full path is not in the appropriate root path (
standardpathorexternalpath, depending onis_standard).ValueError – If the script does not exist or is not a file, is invisible (name starts with “.”) or private (name starts with “_”), or is not executable.
- async move(sal_index, location, location_sal_index)#
Move a script within the queue.
- Parameters:
- Raises:
ValueError – If the script is not queued.
ValueError – If
locationis not one of the supported enum values.ValueError – If location is relative and a script at
location_sal_indexis not queued.
- Return type:
- static next_group_id()#
Get the next group ID.
The group ID is the current TAI date and time as a string in ISO format. It has T separating date and time and no time zone suffix. Here is an example: “2020-01-17T22:59:05.721”
- Return type:
- pop_script_info(sal_index)#
Remove and return information about a script on the queue.
- Parameters:
sal_index (
int) – SAL index of script.- Returns:
Script infor of the removed script.
- Return type:
- Raises:
ValueError – If the script cannot be found on the queue.
- async requeue(sal_index, seq_num, location, location_sal_index)#
Requeue a script.
Add a script that is a copy of an existing script, including the same configuration.
Launch the script in a new subprocess and wait for the subprocess to start. Start a background task to configure the script when it is ready.
- Parameters:
- Raises:
ValueError – If the script
sal_indexcannot be found.ValueError – If
locationis not one of the supported enum values.ValueError – If location is relative and a script
location_sal_indexis not queued.
- Returns:
script_info – Info for the requeued script.
- Return type:
- async set_group_id(script_info)#
Set or clear the group ID for a script.
- Parameters:
script_info (
ScriptInfo) – Script info.- Raises:
RuntimeError – If the group ID cannot be set.
- Return type:
- async stop_one_script(script_info)#
Stop a queued or running script, giving it time to clean up.
First send the script the
stopcommand, giving thattimeouta few seconds to succeed or fail. If necessary, terminate the script by sending SIGTERM to the process.This is slower and than
terminate, but gives the script a chance to clean up. If successful, the script is removed from the queue.- Parameters:
script_info (
ScriptInfo) – Script info for script stop.- Return type:
- async stop_scripts(sal_indices, terminate)#
Stop one or more queued scripts and/or the current script.
Silently ignores scripts that cannot be found or are already stopped.
- async terminate_all()#
Terminate all scripts and return info for the ones terminated.
- Returns:
info_list – ScriptInfo for each terminated script. Excludes zombie script processes (which should be rare), because ScriptInfo is not available for those.
- Return type:
- async terminate_one_script(script_info)#
Terminate a queued or running script.
If successful (as it will be, unless the script catches SIGTERM), the script is removed from the the queue. If you have time please try
stopfirst, as that gives the script a chance to clean up. Ifstopfails then the script will still be terminated.- Parameters:
script_info (
ScriptInfo) – Script info for script terminate.- Raises:
ValueError – If a script is not queued or running.
- Return type: