Module view: Script Execution
Note
Diagrams are embedded as SVG images. If the text is too small, please use your web browser to zoom in to the images, which should be magnified without losing detail. Alternatively open image in a new tab with right click + Open in a new tab.
This view is a module view depicting the key components involved in script execution; that is, creating new Python processes that load a user script and run functions in that user script when requested.
Primary Presentation
Major classes responsible for the execution and management of user scripts.
Element Catalogue
Elements and their properties
Component |
Description |
---|---|
EmbeddedStringScript |
NOT IMPLEMENTED YET
|
Environment is a dataclass that holds the information required to identify a Python virtual environment and its location on disk. In addition, it holds synchronisation primitives to avoid race conditions between multiple requests to create the same environment, as would be the case for multiple requests to create virtual environments for the same git project and git commit hash. |
|
|
EnvironmentManager is responsible for creating and managing Environments, the custom Python virtual environments
in which a user script that requiring a non-default environment runs. Typically, this is the case for a request
to run a script located in a git repository, where the request requires a more recent version of the
ska-oso-scripting library or control scripts than was packaged with the OET.
|
Event |
The Event class manages a flag that can be set and/or inspected by multi Python processes. Events are commonly used to signify to observers of the Event that a condition has occurred. Event is part of the standard Python library. |
EventBusWorker is a QueueProcWorker that relays pubsub events seen in one EventBusWorker process to other EventBusWorker processes. See Module view: Script Execution UI and Service API for more information. |
|
ExecutableScript is an abstract class for any class that defines a Python script to be executed. |
|
|
FilesystemScript captures the information required to run a Python script located within the filesystem of a deployed OET backend. As an example, in a Kubernetes context this could point to a script contained in the default preinstalled scripting environment, or a script made available in a persistent volume mounted by the OET pod. |
GitScript captures the information required to run a Python script that is located in a git repository. It collects a set of identifying information that together can conclusively identify the specific script to be run, such as git repository, branch, tag, and commit hash. |
|
MainContext is the parent context for a set of worker processes that communicate via message queues. It defines
a consistent architecture for event-based communication between Python processes and consistent behaviour for
POSIX signal handling and process management.
|
|
MPQueue is an extension of the standard library multiprocessing.Queue that adds get/set methods that return booleans when the operation fails rather than raising exceptions, which makes the class easier to use in some contexts. |
|
Proc represents a child Python process of a MainContext.
|
|
ProcedureInput captures the anonymous positional arguments and named keyword arguments for a Python function call. ProcedureInput is used in the presentation model to help describe historic function calls as well as in the PrepareProcessCommand and StartProcessCommand to define the arguments for an upcoming call. |
|
ProcedureState is an enumeration defining the states that a Procedure (a child ScriptWorker process running a Python script) can be in. The states are:
|
|
ProcessManager is the parent for all script execution processes. Specifically, it is the parent of all the
ScriptWorker instances that run user code in a child Python process. ProcessManager is responsible for launching
ScriptWorker processes and communicating relaying requests such as ‘load user script X from git repository
Y’ ‘run main() function’ or ‘stop execution’ to the running scripts.
|
|
ProcWorker is a template class for code that should execute in a child Python interpreter process.
|
|
Queue |
Queue is a class that implements a multi-consumer, multi-producer FIFO queue that can be shared between Python processes. Queue is part of the standard Python library. |
QueueProcWorker is a ProcWorker that loops over items received on a message queue, calling the abstract main_func() function for every item received. Together with the ProcWorker base class functionality, QueueProcWorker will call main_func() for every event received for as long as the shutdown event is not set. |
|
ScriptExecutionService provides the high-level API for the script execution domain, presenting methods that
‘start script _Y_’ or ‘run method _Y_ of user script _Z_’. The ScriptExecutionService orchestrates control of the
ProcessManager and associated domain objects in order to satisfy an API request.
|
|
ScriptWorker is a class that can load a user script in a child process, running functions of that user script on
request.
|
Element Interfaces
The major public interface in these interactions is the ScriptExecutionService API. For more information on this
interface, please see the API documentation for
ScriptExecutionService
.
Element Behaviour
ScriptExecutionService
The sequence diagram below gives a high-level overview of how the
ScriptExecutionService
controls objects in the domain module to
meet requests to prepare, start, and stop user script execution.
ScriptExecutionService.prepare
The diagram below gives more detail on how the domain layer handles a request to prepare a script for execution.
ScriptWorker
The diagram below illustrates how a ScriptWorker
is created and how it
communicates startup success with the parent process.
ScriptWorker.main_loop
The diagram below depicts the main ScriptWorker
message loop, illustrating how
the various messages from the parent ProcessManager
are handled by child
ScriptWorker
.
Context Diagram
Variability Guide
N/A
Rationale
The figure below shows the state diagram for a Procedure. The diagram omits failure states STOPPED and FAILED as
these can be reached from any of the states. The procedure states from CREATING to READY describe the preparing
of the script, which includes setting up the script environment, loading the script to memory and running the init
function if one is present. Currently the Procedure state moves to COMPLETE once a function called main
has been
run but this could be a temporary design decision if the need for running multiple functions/the same function multiple
times arises.