climate_ref_celery.routing
#
Queue routing for Celery task submission
A deployment may wish to place executions on different queues depending on their size.
The routing table maps diagnostics to queue names,
so that each execution lands on a queue such as esmvaltool-large.
Differently sized worker pools can then consume the queues independently.
The table is a TOML file whose path is given by the REF_CELERY_ROUTES environment variable.
When the variable is unset, no table is loaded and every execution uses the bare provider queue.
Example:
.. code-block:: toml
default = "{provider}"
[esmvaltool]
default = "esmvaltool-medium"
rules = [
{ match = "portrait-*", queue = "esmvaltool-large" },
{ match = "sea-ice-basic", queue = "esmvaltool-small" },
]
[ilamb]
default = "ilamb-small"
Rules are matched against the diagnostic slug in order, first match wins.
Patterns use :func:fnmatch.fnmatchcase semantics, so exact strings and glob wildcards both work.
Queue names are templates in which {provider} expands to the provider slug.
A provider default applies when no rule matches.
The top-level default applies when the provider has no entry.
With no default and no match, the queue is the bare provider slug,
equivalent to a default of "{provider}".
ROUTES_ENV_VAR = 'REF_CELERY_ROUTES'
module-attribute
#
Environment variable holding the path to the routing table file
ProviderRoutes
#
The ordered rules and optional default queue for one provider
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
queue_template_for(diagnostic_slug)
#
Resolve the queue template for a diagnostic, or the provider default if no rule matches
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
RoutingRule
#
A single pattern to queue rule
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
RoutingTable
#
Deployment-supplied mapping of diagnostics to queue names
An empty table routes everything to the bare provider queue,
which matches the behaviour when no table is configured,
i.e. default = "{provider}".
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
from_file(path, known_providers=None)
classmethod
#
Load and validate a routing table from a TOML file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the TOML file |
required |
known_providers
|
Collection[str] | None
|
Slugs of the currently registered providers.
An entry for a provider not in this collection logs a warning, not an error,
because deployments may share one table across environments with different provider sets.
|
None
|
Raises:
| Type | Description |
|---|---|
RoutingTableError
|
The file is missing, is not valid TOML, or contains a malformed entry |
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
queue_for(provider_slug, diagnostic_slug)
#
Compute the queue name for an execution
Returns:
| Type | Description |
|---|---|
str
|
The matched queue template with |
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
RoutingTableError
#
Bases: ValueError
Raised when a routing table file is malformed
A malformed table fails hard rather than falling back to default routing, because silent fallback would misplace large jobs onto small workers.
Source code in packages/climate-ref-celery/src/climate_ref_celery/routing.py
load_routing_table(known_providers=None)
#
Load the routing table named by REF_CELERY_ROUTES, or an empty table if unset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
known_providers
|
Collection[str] | None
|
Slugs of the currently registered providers, used to warn about stale entries.
|
None
|
Raises:
| Type | Description |
|---|---|
RoutingTableError
|
The variable is set but the file is missing or malformed |