sandloom-celery 0.7.0a14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sandloom_celery-0.7.0a14/.gitignore +4 -0
- sandloom_celery-0.7.0a14/CHANGELOG.md +27 -0
- sandloom_celery-0.7.0a14/LICENSE +202 -0
- sandloom_celery-0.7.0a14/NOTICE +8 -0
- sandloom_celery-0.7.0a14/PKG-INFO +63 -0
- sandloom_celery-0.7.0a14/README.md +46 -0
- sandloom_celery-0.7.0a14/pyproject.toml +34 -0
- sandloom_celery-0.7.0a14/src/sandloom_celery/__init__.py +9 -0
- sandloom_celery-0.7.0a14/src/sandloom_celery/broker_probe.py +96 -0
- sandloom_celery-0.7.0a14/src/sandloom_celery/taskqueue.py +453 -0
- sandloom_celery-0.7.0a14/src/sandloom_celery/worker.py +1390 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog — sandloom-celery
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [0.7.0a14] — 2026-11-16
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
|
|
9
|
+
- **The `celery` task queue driver fills only `health_timeout_seconds` from a setting** (idk-flat-urls-z). `BROKER_URL` and `CACHE_URL` are removed settings: the broker is the `broker` option of the `taskqueue` instance and the result backend is the `backend` option, off unless stated. The driver's `settings_fill` keeps the readiness probe's bound (`HEALTH_CHECK_TIMEOUT_SECONDS` into `health_timeout_seconds`, as cap and bound). Upgrade: [Upgrading to 0.7.0a14](https://sandloom.dev/docs/operate/upgrade/#upgrading-to-070a14-the-flat-redis-settings).
|
|
10
|
+
|
|
11
|
+
### Security
|
|
12
|
+
|
|
13
|
+
- **The app a `taskqueue` provider publishes through refuses a `CELERY_*` broker or backend that differs from `INFRA`** (idk-flat-urls-z). Celery's `app.conf` prefers `CELERY_BROKER_URL`, `CELERY_BROKER_READ_URL`, `CELERY_BROKER_WRITE_URL` and `CELERY_RESULT_BACKEND` (and a config module) over the url the app was built with, so a stray one silently redirected every publish. On the provider's first use its final `app.conf` is compared with the instance's `broker` and `backend` and a difference raises `ForeignCeleryConfError`, not an outage (nothing was sent), naming the option and the instance, never a url. A value equal to `INFRA`, or blank, passes. The importable app already did this. The check also refuses any `broker_transport`, `broker_host`, `broker_port`, `broker_vhost`, `broker_user` or `broker_password` in the conf (`broker_transport = "memory"` sank every publish into an in-process queue; the others filled in what the `INFRA` url omitted), and it runs on every use of the app, not only the first, so a `CELERY_BROKER_URL` set later is refused too. It also refuses a `broker_use_ssl` that is anything but absent, `None` or `False` (kombu merges a dict there into the connection after the url: `host`, `port`, `password` and `virtual_host` redirected it, `ssl_cert_reqs: CERT_NONE` turned certificate verification off for a `rediss://` url; `True` made a `rediss://` connection fall back to plain text and send the password in the clear; TLS comes from the scheme and the url's query) and a `redis_host`, `redis_port`, `redis_db`, `redis_username`, `redis_password`, `redis_backend_use_ssl` or `redis_backend_credential_provider`, which the redis result backend takes where its url omits the part. `broker_transport_options` and `result_backend_transport_options` accept only an allow-list of tuning keys (timeouts, keep-alive, pool size, key prefix, retry and visibility options, listed in `docs/modules/background/tasks.md`): an `amqp://` broker takes its host, user, password and `ssl` from them, and a `sentinel://` broker its master, so any other key is refused, named by its option only. Every broker scheme stays supported.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **A startup warning when the broker is the cache's Redis database** (idk-flat-urls-no-follows). `CeleryTaskQueueProvider.aopen` registers the broker's `host:port/db` in `sandloom.driverkit.shared_endpoints` and logs one WARNING when it is the endpoint of `cache.default`: a cache that evicts can drop queued tasks. The log names both instances and never carries the broker's password; nothing is refused, and the package imports no other driver package. A queue the kernel synthesized is logged at INFO. `aclose` unregisters the queue.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Add the Celery driver `taskqueue.celery` and its worker and scheduler host as an optional package. They left the kernel wheel; `sandloom[celery]` installs this package.
|
|
22
|
+
- **`celery -A sandloom_celery.worker` reads its broker from `INFRA`, not from the `BROKER_URL` variable** (idk-flat-urls-c). The importable app (`app`, `celery`, `celery_app`; for `celery inspect`, `call`, `status` and Flower) is built, on first use and with no import side effect, from the options of the `default` task queue as the application resolves them: `Settings` (environment and `.env`), the composition's selection, `INFRA` over it. State the broker as `INFRA='{"taskqueue":{"default":{"broker":"redis://..."}}}'`. Without one the lookup raises `AttributeError` naming `taskqueue.default.broker`, and a `default` task queue that is not the `celery` driver is refused with a message saying so. The module no longer reads `os.environ["BROKER_URL"]` (`BROKER_URL_ENV` is removed). A stray `BROKER_URL` in the environment still cannot replace the broker of a worker or a beat: `sandloom worker` and `sandloom beat` keep hiding Celery's own `BROKER_URL` option variable for the run. The importable app is stricter than before about the same variables: Celery's CLI writes `CELERY_BROKER_URL` from `-b` / `BROKER_URL` and `CELERY_RESULT_BACKEND` from `--result-backend` / `RESULT_BACKEND`, and `app.conf` prefers them over the app's own broker, so the app raises `AttributeError` naming the variable (never its value) when `CELERY_BROKER_URL`, `CELERY_BROKER_READ_URL`, `CELERY_BROKER_WRITE_URL` or `CELERY_RESULT_BACKEND` is set to something other than what `INFRA` states. A value equal to `INFRA`'s, or a blank one, passes. The app also compares its finished `app.conf` (`broker_url`, `broker_read_url`, `broker_write_url`, `result_backend`) with `INFRA` and raises `AttributeError` naming the option when one differs, because a config module (`celery --config X`, `CELERY_CONFIG_MODULE`) or the default loader (`--loader default` imports `celeryconfig.py` from the working directory) can set a write broker or a result backend that the environment check does not see; the check also runs when the provider built the process-wide app first, and `celery -A sandloom_celery.worker` gets no app out of a refusal: the module keeps the process-wide app in a holder, not in a module-level name, because Celery's `-A` lookup falls back to any `Celery` instance in the module once `app` and `celery` raise. Upgrade: a service that ran `celery -A sandloom_celery.worker ...` with only `BROKER_URL` set (and no `INFRA`) puts the broker into `INFRA` as above; the kernel refuses `BROKER_URL` at startup.
|
|
23
|
+
- **`backend` has no default and is documented as optional** (idk-flat-urls-c). Sandloom never reads a task result (`task_ignore_result` is on), so an instance that states no `backend` runs with no result backend. The kernel fills nothing: leave `backend` out of `INFRA` unless you read results. The importable app now takes the same `backend` as the provider's `default` instance (before: always none).
|
|
24
|
+
- **The importable app needs the kernel's configuration to be valid.** Reading `INFRA` loads `Settings`, so an invalid configuration (for example a missing `DATABASE_URL`) stops `celery -A sandloom_celery.worker` with the configuration error, where it used to start from `BROKER_URL` alone.
|
|
25
|
+
- **A `celery` task-queue instance with no broker is refused at startup, and the message names the INFRA option** (idk-flat-urls-s0a). The build raises `MissingBrokerError` (a `ValueError`, `fatal_at_startup`) saying `celery taskqueue instance 'default' has no 'broker' option: set the INFRA option taskqueue.default.broker, e.g. INFRA='{...}'`.
|
|
26
|
+
- **An app the conf check refuses never becomes `celery.current_app`** (idk-low5-product). The driver built its apps with `Celery(...)`, which makes the new app current at construction, so an app refused for a foreign broker or result backend stayed the process's current app. It now builds with `set_as_current=False` and calls `app.set_current()` once the check has passed, for the provider's app and for the importable one.
|
|
27
|
+
- **`redis>=5.2.1,<6` is a dependency of its own, and `hiredis` is an optional extra** (idk-low5-product). `celery[redis]` accepted any redis release; the bound is the one `sandloom-redis` has. `pip install sandloom-celery[hiredis]` adds the hiredis parser.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Sandloom
|
|
2
|
+
Copyright 2026 Vasyl Cherniavskyi
|
|
3
|
+
|
|
4
|
+
The original Sandloom framework code, documentation and examples are licensed
|
|
5
|
+
under the Apache License, Version 2.0. See LICENSE for the full terms.
|
|
6
|
+
|
|
7
|
+
Third-party components and assets retain their own copyright notices and
|
|
8
|
+
licenses. This notice does not replace or modify those terms.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sandloom-celery
|
|
3
|
+
Version: 0.7.0a14
|
|
4
|
+
Summary: Celery driver for Sandloom: taskqueue, worker host and scheduler
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: celery[redis]<6,>=5.6.3
|
|
10
|
+
Requires-Dist: orjson<4,>=3.13.0
|
|
11
|
+
Requires-Dist: pydantic<3,>=2
|
|
12
|
+
Requires-Dist: redis<6,>=5.2.1
|
|
13
|
+
Requires-Dist: sandloom<0.8,>=0.7.0a14
|
|
14
|
+
Provides-Extra: hiredis
|
|
15
|
+
Requires-Dist: redis[hiredis]<6,>=5.2.1; extra == 'hiredis'
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Sandloom Celery driver
|
|
19
|
+
|
|
20
|
+
Install this package alongside the matching Sandloom release: `pip install
|
|
21
|
+
'sandloom[celery]'` brings it in, and a checkout runs `uv pip install -e
|
|
22
|
+
packages/sandloom -e packages/sandloom-celery` from the repository root.
|
|
23
|
+
Sandloom discovers the driver through the `sandloom.drivers` entry-point group.
|
|
24
|
+
|
|
25
|
+
| Entry point | Capability | Provider |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| `taskqueue.celery` | `taskqueue` | `sandloom_celery.taskqueue:CeleryTaskQueueProvider` |
|
|
28
|
+
|
|
29
|
+
The driver declares the tier `beta`. Its worker and scheduler host
|
|
30
|
+
(`sandloom_celery.worker`, reached through `TaskQueueProvider.worker_host()`)
|
|
31
|
+
runs `sandloom worker` and `sandloom beat`. The `celery` instance options
|
|
32
|
+
`worker_pool` (`prefork`, `solo` or `threads`) and `health_timeout_seconds` are
|
|
33
|
+
set in `INFRA`:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
INFRA='{"taskqueue":{"default":{"driver":"celery","worker_pool":"threads"}}}'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**macOS.** The default `prefork` pool spawns its children there, and a spawned
|
|
40
|
+
child never sees the task table the host registered at boot; the host refuses
|
|
41
|
+
to start with `prefork` on macOS. Set `worker_pool` to `solo` or `threads`.
|
|
42
|
+
|
|
43
|
+
**The importable Celery app.** `celery -A sandloom_celery.worker inspect active`
|
|
44
|
+
(and `call`, `status`, Flower) use the `default` app, built from the broker of the
|
|
45
|
+
`default` task queue (`INFRA.taskqueue.default.broker`, read through `Settings`
|
|
46
|
+
when the app is first used, for the `taskqueue` capability only; no `BROKER_URL`
|
|
47
|
+
of its own). A missing broker is an error naming that option. Celery's own CLI
|
|
48
|
+
writes `CELERY_BROKER_URL` from `-b` / `BROKER_URL` and `CELERY_RESULT_BACKEND`
|
|
49
|
+
from `--result-backend` / `RESULT_BACKEND`, and `app.conf` prefers them, so the app
|
|
50
|
+
refuses a `CELERY_BROKER_URL`, `CELERY_BROKER_READ_URL`, `CELERY_BROKER_WRITE_URL` or
|
|
51
|
+
`CELERY_RESULT_BACKEND` that differs from `INFRA`, naming the variable, never its value.
|
|
52
|
+
It also compares the finished `app.conf` (`broker_url`, `broker_read_url`,
|
|
53
|
+
`broker_write_url`, `result_backend`) with `INFRA` and refuses a difference, naming
|
|
54
|
+
the option: a config module (`celery --config`, `CELERY_CONFIG_MODULE`) or the default
|
|
55
|
+
loader (`--loader default` reads `celeryconfig.py` from the working directory) can
|
|
56
|
+
set them. It registers no task, and `celery -A sandloom_celery.worker worker|beat` refuses
|
|
57
|
+
to start: run `sandloom worker` and `sandloom beat` instead.
|
|
58
|
+
|
|
59
|
+
**No result backend.** Sandloom never reads a task result, so an instance runs
|
|
60
|
+
with no result backend unless it states `backend` in `INFRA`.
|
|
61
|
+
|
|
62
|
+
The tests of this driver still run with the kernel's suite; they move into this
|
|
63
|
+
package with its own CI lane against a real broker.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Sandloom Celery driver
|
|
2
|
+
|
|
3
|
+
Install this package alongside the matching Sandloom release: `pip install
|
|
4
|
+
'sandloom[celery]'` brings it in, and a checkout runs `uv pip install -e
|
|
5
|
+
packages/sandloom -e packages/sandloom-celery` from the repository root.
|
|
6
|
+
Sandloom discovers the driver through the `sandloom.drivers` entry-point group.
|
|
7
|
+
|
|
8
|
+
| Entry point | Capability | Provider |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| `taskqueue.celery` | `taskqueue` | `sandloom_celery.taskqueue:CeleryTaskQueueProvider` |
|
|
11
|
+
|
|
12
|
+
The driver declares the tier `beta`. Its worker and scheduler host
|
|
13
|
+
(`sandloom_celery.worker`, reached through `TaskQueueProvider.worker_host()`)
|
|
14
|
+
runs `sandloom worker` and `sandloom beat`. The `celery` instance options
|
|
15
|
+
`worker_pool` (`prefork`, `solo` or `threads`) and `health_timeout_seconds` are
|
|
16
|
+
set in `INFRA`:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
INFRA='{"taskqueue":{"default":{"driver":"celery","worker_pool":"threads"}}}'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**macOS.** The default `prefork` pool spawns its children there, and a spawned
|
|
23
|
+
child never sees the task table the host registered at boot; the host refuses
|
|
24
|
+
to start with `prefork` on macOS. Set `worker_pool` to `solo` or `threads`.
|
|
25
|
+
|
|
26
|
+
**The importable Celery app.** `celery -A sandloom_celery.worker inspect active`
|
|
27
|
+
(and `call`, `status`, Flower) use the `default` app, built from the broker of the
|
|
28
|
+
`default` task queue (`INFRA.taskqueue.default.broker`, read through `Settings`
|
|
29
|
+
when the app is first used, for the `taskqueue` capability only; no `BROKER_URL`
|
|
30
|
+
of its own). A missing broker is an error naming that option. Celery's own CLI
|
|
31
|
+
writes `CELERY_BROKER_URL` from `-b` / `BROKER_URL` and `CELERY_RESULT_BACKEND`
|
|
32
|
+
from `--result-backend` / `RESULT_BACKEND`, and `app.conf` prefers them, so the app
|
|
33
|
+
refuses a `CELERY_BROKER_URL`, `CELERY_BROKER_READ_URL`, `CELERY_BROKER_WRITE_URL` or
|
|
34
|
+
`CELERY_RESULT_BACKEND` that differs from `INFRA`, naming the variable, never its value.
|
|
35
|
+
It also compares the finished `app.conf` (`broker_url`, `broker_read_url`,
|
|
36
|
+
`broker_write_url`, `result_backend`) with `INFRA` and refuses a difference, naming
|
|
37
|
+
the option: a config module (`celery --config`, `CELERY_CONFIG_MODULE`) or the default
|
|
38
|
+
loader (`--loader default` reads `celeryconfig.py` from the working directory) can
|
|
39
|
+
set them. It registers no task, and `celery -A sandloom_celery.worker worker|beat` refuses
|
|
40
|
+
to start: run `sandloom worker` and `sandloom beat` instead.
|
|
41
|
+
|
|
42
|
+
**No result backend.** Sandloom never reads a task result, so an instance runs
|
|
43
|
+
with no result backend unless it states `backend` in `INFRA`.
|
|
44
|
+
|
|
45
|
+
The tests of this driver still run with the kernel's suite; they move into this
|
|
46
|
+
package with its own CI lane against a real broker.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sandloom-celery"
|
|
3
|
+
version = "0.7.0a14"
|
|
4
|
+
description = "Celery driver for Sandloom: taskqueue, worker host and scheduler"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
9
|
+
dependencies = [
|
|
10
|
+
"sandloom>=0.7.0a14,<0.8",
|
|
11
|
+
"pydantic>=2,<3",
|
|
12
|
+
"orjson>=3.13.0,<4",
|
|
13
|
+
"celery[redis]>=5.6.3,<6",
|
|
14
|
+
# The same bound as sandloom-redis: the Redis client is imported through the
|
|
15
|
+
# celery extra, which would otherwise accept any release.
|
|
16
|
+
"redis>=5.2.1,<6",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
# The hiredis parser of the Redis client (faster reply parsing); optional.
|
|
21
|
+
hiredis = ["redis[hiredis]>=5.2.1,<6"]
|
|
22
|
+
|
|
23
|
+
[project.entry-points."sandloom.drivers"]
|
|
24
|
+
"taskqueue.celery" = "sandloom_celery.taskqueue:CeleryTaskQueueProvider"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["hatchling>=1.27"]
|
|
28
|
+
build-backend = "hatchling.build"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/sandloom_celery"]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.sdist]
|
|
34
|
+
include = ["/src", "/LICENSE", "/NOTICE", "/README.md", "/CHANGELOG.md", "/pyproject.toml"]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Celery driver for Sandloom.
|
|
2
|
+
|
|
3
|
+
Three modules: ``taskqueue`` (the ``celery`` taskqueue driver), ``worker`` (its
|
|
4
|
+
worker and scheduler host, and the importable Celery app of
|
|
5
|
+
``celery -A sandloom_celery.worker``) and ``broker_probe`` (the bounded broker
|
|
6
|
+
connection behind ``health()``). The driver registers through the
|
|
7
|
+
``sandloom.drivers`` entry-point group and imports only ``sandloom.driverkit``;
|
|
8
|
+
Celery loads when a provider is built, not at import.
|
|
9
|
+
"""
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""The broker probe of the ``celery`` taskqueue driver (``sandloom-celery``).
|
|
2
|
+
|
|
3
|
+
``CeleryTaskQueueProvider.health()`` answers with :func:`probe_broker`: one
|
|
4
|
+
kombu connection to the app's broker, opened and released, bounded by
|
|
5
|
+
the ``health_timeout_seconds`` option (the connect timeout and, for the Redis
|
|
6
|
+
transports, the socket timeouts), with no retry. Building the provider sends
|
|
7
|
+
nothing to the broker, so without this probe a broker outage was invisible to
|
|
8
|
+
every health reader (``/ready``, ``/diagnostics/infra``, ``sandloom doctor``).
|
|
9
|
+
|
|
10
|
+
The probe is not cached here: its readers are. ``/ready`` runs it through the
|
|
11
|
+
TTL / single-flight cache of the readiness probes (one probe per instance per
|
|
12
|
+
TTL, however many hits arrive); ``/diagnostics/infra`` and ``sandloom doctor``
|
|
13
|
+
are operator calls behind a credential or a shell.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import asyncio
|
|
19
|
+
from typing import Any
|
|
20
|
+
from urllib.parse import urlsplit
|
|
21
|
+
|
|
22
|
+
from sandloom.driverkit import HealthResult
|
|
23
|
+
|
|
24
|
+
#: Broker URL schemes of the kombu Redis transports, which take their socket
|
|
25
|
+
#: timeouts from the transport options (``connect_timeout`` alone does not
|
|
26
|
+
#: bound them).
|
|
27
|
+
_REDIS_SCHEMES = frozenset({"redis", "rediss", "sentinel"})
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _transport_options(app: Any, scheme: str, timeout: float) -> dict[str, Any]:
|
|
31
|
+
options = dict(getattr(app.conf, "broker_transport_options", None) or {})
|
|
32
|
+
if scheme in _REDIS_SCHEMES:
|
|
33
|
+
# An operator's own socket timeouts win; the probe only bounds what
|
|
34
|
+
# is unset.
|
|
35
|
+
options.setdefault("socket_connect_timeout", timeout)
|
|
36
|
+
options.setdefault("socket_timeout", timeout)
|
|
37
|
+
return options
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _connect_once(app: Any, timeout: float) -> None:
|
|
41
|
+
"""Open one connection to ``app``'s broker and release it (blocking)."""
|
|
42
|
+
url = str(getattr(app.conf, "broker_url", None) or "")
|
|
43
|
+
scheme = urlsplit(url).scheme if url else ""
|
|
44
|
+
connection = app.connection_for_write(
|
|
45
|
+
connect_timeout=timeout,
|
|
46
|
+
transport_options=_transport_options(app, scheme, timeout),
|
|
47
|
+
)
|
|
48
|
+
try:
|
|
49
|
+
connection.ensure_connection(
|
|
50
|
+
max_retries=1,
|
|
51
|
+
interval_start=0,
|
|
52
|
+
interval_step=0,
|
|
53
|
+
interval_max=0,
|
|
54
|
+
timeout=timeout,
|
|
55
|
+
)
|
|
56
|
+
finally:
|
|
57
|
+
connection.release()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class BrokerUnreachableError(RuntimeError):
|
|
61
|
+
"""The broker refused or dropped the probe's connection (any transport
|
|
62
|
+
error); the message carries the error's type name and nothing of the broker
|
|
63
|
+
(no URL, no credential, no host): a health detail reaches an operator
|
|
64
|
+
endpoint, a log and a metric label."""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def probe_broker(app: Any, *, limit_seconds: float) -> HealthResult:
|
|
68
|
+
"""``ok`` when ``app``'s broker accepts a connection within
|
|
69
|
+
``limit_seconds`` (the driver's ``health_timeout_seconds`` option, which
|
|
70
|
+
the kernel fills from ``HEALTH_CHECK_TIMEOUT_SECONDS``); ``fail`` with
|
|
71
|
+
the details ``{"error": "timeout"}`` (one token, the shape of every health
|
|
72
|
+
detail) when it does not answer in time. A refused or dropped connection
|
|
73
|
+
raises :class:`BrokerUnreachableError`, which
|
|
74
|
+
``CeleryTaskQueueProvider.health`` turns into a failed probe carrying its
|
|
75
|
+
type name, never its text (spec 2.4); any other reader of the probe does the
|
|
76
|
+
same. No detail names the broker.
|
|
77
|
+
|
|
78
|
+
The blocking connect runs in a worker thread, so the event loop never
|
|
79
|
+
waits on the broker; the connect and socket timeouts end that thread
|
|
80
|
+
too, so an unreachable broker never leaves one behind.
|
|
81
|
+
"""
|
|
82
|
+
try:
|
|
83
|
+
await asyncio.wait_for(
|
|
84
|
+
asyncio.to_thread(_connect_once, app, limit_seconds), limit_seconds
|
|
85
|
+
)
|
|
86
|
+
except TimeoutError:
|
|
87
|
+
return HealthResult(status="fail", details={"error": "timeout"})
|
|
88
|
+
except Exception as exc:
|
|
89
|
+
# The type name only: a client error's text can carry the broker URL.
|
|
90
|
+
raise BrokerUnreachableError(
|
|
91
|
+
f"broker unreachable: {type(exc).__name__}"
|
|
92
|
+
) from exc
|
|
93
|
+
return HealthResult(status="ok")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
__all__ = ["BrokerUnreachableError", "probe_broker"]
|