logical_worker_manager
Module for managing logical worker entities.
This module defines the LogicalWorkerManager class, which provides high-level operations
for creating, retrieving, and deleting logical workers stored in the database. It extends
the generic EntityManager class
with logic specific to logical worker entities, such as ID resolution based on worker name
and queues.
The manager also integrates cleanup routines to maintain consistency across related entities, e.g., by removing logical workers from associated runs before deletion.
LogicalWorkerManager
Bases: EntityManager[LogicalWorkerEntity, LogicalWorkerModel]
Manager class for handling logical worker entities.
This class provides methods to create, retrieve, and delete logical workers from the backend. It also handles internal ID resolution and cleanup of references to logical workers from related entities such as runs.
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
The backend interface used for storing and retrieving logical workers. |
|
db |
Reference to the main database interface, used for cross-entity operations such as detaching workers from runs. |
|
_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 logical worker with the given name and queue list. |
get |
Retrieve a logical worker either by ID or by name and queues. |
get_all |
Retrieve all logical workers in the system. |
delete |
Delete a logical worker and remove it from all associated runs. |
delete_all |
Delete all logical workers currently stored in the backend. |
set_db_reference |
Set a reference to the main database object for accessing related entities. |
Source code in merlin/db_scripts/entity_managers/logical_worker_manager.py
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 | |
__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/logical_worker_manager.py
create(name, queues)
Create a new logical worker entity, or return it if it already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the logical worker. |
required |
queues
|
List[str]
|
A list of queue names the worker is assigned to. |
required |
Returns:
| Type | Description |
|---|---|
LogicalWorkerEntity
|
The created or existing logical worker entity. |
Source code in merlin/db_scripts/entity_managers/logical_worker_manager.py
delete(worker_id=None, worker_name=None, queues=None)
Delete a logical worker entity and clean up any references from associated runs.
The method ensures the logical worker is removed from all runs that reference it before deleting it from the backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker_id
|
str
|
The ID of the logical worker. |
None
|
worker_name
|
str
|
The name of the logical worker. |
None
|
queues
|
List[str]
|
The queues the worker handles. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If input arguments are invalid or insufficient. |
Source code in merlin/db_scripts/entity_managers/logical_worker_manager.py
delete_all()
Delete all logical worker entities currently stored in the backend.
Runs cleanup on each logical worker before deletion to remove dependencies.
Source code in merlin/db_scripts/entity_managers/logical_worker_manager.py
get(worker_id=None, worker_name=None, queues=None)
Retrieve a logical worker entity by ID, or by name and queues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker_id
|
str
|
The unique identifier of the logical worker. |
None
|
worker_name
|
str
|
The name of the logical worker. |
None
|
queues
|
List[str]
|
The queues the worker handles. |
None
|
Returns:
| Type | Description |
|---|---|
LogicalWorkerEntity
|
The retrieved logical worker entity. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input arguments are invalid or insufficient. |
WorkerNotFoundError
|
If the specified worker does not exist. |
Source code in merlin/db_scripts/entity_managers/logical_worker_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., runs) 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 |