run_manager
Module for managing run entities within the Merlin database.
This module defines the RunManager class, which extends the generic
EntityManager base
class to provide CRUD operations for runs associated with studies, workspaces,
and queues. The manager coordinates with the study and logical worker managers
for consistent data handling during create and delete operations.
RunManager
Bases: EntityManager[RunEntity, RunModel]
Manager for run entities.
This class handles creation, retrieval, updating, and deletion of runs in the database. It maintains consistency by coordinating with study and logical worker entities during operations such as run creation and deletion.
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
The database backend used for storing run entities. |
|
db |
Reference to the main Merlin database, allowing access to other entity managers such as studies and logical workers. |
|
_filter_accessor_map |
Dict[str, Callable[[T], Any]]
|
A dictionary mapping supported filter keys to accessor functions
for the entity type. Used by filtering logic (e.g., in |
Methods:
| Name | Description |
|---|---|
create |
Create a new run associated with a study and workspace. |
get |
Retrieve a run by its ID or workspace identifier. |
get_all |
Retrieve all runs from the database. |
delete |
Delete a run and perform cleanup of related entities. |
delete_all |
Delete all runs in the database. |
set_db_reference |
Set the reference to the main Merlin database for cross-entity operations. |
Source code in merlin/db_scripts/entity_managers/run_manager.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
__init__(backend)
Initialize the PhysicalWorkerManager with the given backend.
This sets up the manager to handle physical worker entities by specifying the associated entity class and entity type string. These are used by the base EntityManager to perform generic operations like retrieving and filtering entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ResultsBackend
|
The backend used to persist and retrieve physical worker data. |
required |
Source code in merlin/db_scripts/entity_managers/run_manager.py
create(study_name, workspace, queues, **kwargs)
Create a new run associated with a study, workspace, and queues.
This method ensures the study exists (creating it if necessary), then creates
and saves a new run entity. Additional keyword arguments that correspond to valid
RunModel fields are included; other kwargs are
stored as additional data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_name
|
str
|
Name of the study this run belongs to. |
required |
workspace
|
str
|
Workspace identifier for the run. |
required |
queues
|
List[str]
|
List of queues associated with the run. |
required |
**kwargs
|
Any
|
Additional optional fields for the run entity. |
{}
|
Returns:
| Type | Description |
|---|---|
RunEntity
|
The created run entity. |
Source code in merlin/db_scripts/entity_managers/run_manager.py
delete(run_id_or_workspace)
Delete a run entity by its ID or workspace identifier.
Performs cleanup operations to maintain consistency:
- Removes the run from its associated study.
- Removes the run from all logical workers referencing it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id_or_workspace
|
str
|
The unique identifier or workspace string of the run to delete. |
required |
Raises:
| Type | Description |
|---|---|
RunNotFoundError
|
If no run is found matching the identifier. |
Source code in merlin/db_scripts/entity_managers/run_manager.py
delete_all()
Delete all run entities from the database.
This method calls delete on each run entity to ensure proper cleanup.
Source code in merlin/db_scripts/entity_managers/run_manager.py
get(run_id_or_workspace)
Retrieve a run entity by its unique ID or workspace identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id_or_workspace
|
str
|
The unique identifier or workspace string of the run. |
required |
Returns:
| Type | Description |
|---|---|
RunEntity
|
The run entity corresponding to the given identifier. |
Raises:
| Type | Description |
|---|---|
RunNotFoundError
|
If no run is found matching the identifier. |
Source code in merlin/db_scripts/entity_managers/run_manager.py
get_all(filters=None)
Retrieve all run entities managed by this run entity manager, optionally filtered by attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
Dict[str, Any]
|
A dictionary of filter keys and values used to narrow down the query results. Filter keys must correspond to supported filters defined in the ENTITY_REGISTRY for the run entity type. Values are compared against entity attributes or accessor methods (e.g., {"name": "foo"}, {"queues": ["queue1", "queue2"]}). |
None
|
Returns:
| Type | Description |
|---|---|
List[RunEntity]
|
A list of all entities of the specified type matching the filters. |
Source code in merlin/db_scripts/entity_managers/run_manager.py
set_db_reference(db)
Set a reference to the main Merlin database object for cross-entity operations.
This allows the manager to access other entity managers (e.g., logical workers) when performing operations like cleanup during deletions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
MerlinDatabase
|
The database object that provides access to related entity managers. |
required |