Celery DI/AOP integration plugin for Spakky Framework
Project description
spakky-celery
Celery integration plugin for Spakky Framework.
Provides AOP-based automatic task dispatch and periodic schedule registration —
methods decorated with @task or @schedule are intercepted and routed to Celery
without explicit dispatcher calls.
Installation
pip install spakky-celery
Requires:
spakky-task(installed automatically as a dependency)
Features
- AOP-based dispatch:
@taskmethods are intercepted by aspects — no manualdispatch()calls - Broker dispatch: All
@taskcalls are sent to the Celery broker viasend_task() - Schedule registration:
@schedulemethods are registered to Celery Beat automatically - Worker-context detection: Uses a context key to prevent re-dispatch inside workers
- Auto-registration:
@TaskHandlerpods are scanned and registered as Celery tasks automatically - Full configuration: Broker URL, serializer, timezone, and more via environment variables
Configuration
Set environment variables with the SPAKKY_CELERY__ prefix:
| Variable | Default | Description |
|---|---|---|
SPAKKY_CELERY__BROKER_URL |
(required) | Celery broker URL (e.g., amqp://user:pass@host:5672//) |
SPAKKY_CELERY__RESULT_BACKEND |
None |
Result backend URL. None disables result storage |
SPAKKY_CELERY__APP_NAME |
spakky-celery |
Celery application name |
SPAKKY_CELERY__TASK_SERIALIZER |
json |
Task message serializer (json, pickle, yaml, msgpack) |
SPAKKY_CELERY__RESULT_SERIALIZER |
json |
Result serializer |
SPAKKY_CELERY__ACCEPT_CONTENT |
["json"] |
Accepted content types |
SPAKKY_CELERY__TIMEZONE |
UTC |
IANA timezone (e.g., Asia/Seoul) |
SPAKKY_CELERY__ENABLE_UTC |
true |
Use UTC for internal datetime handling |
Usage
1. Define task handlers
from datetime import time, timedelta
from spakky.task import TaskHandler, Crontab, Weekday, task, schedule
@TaskHandler()
class EmailTaskHandler:
@task
def send_email(self, to: str, subject: str, body: str) -> None:
"""Dispatched to Celery broker via send_task()."""
send_smtp(to, subject, body)
@TaskHandler()
class MaintenanceHandler:
@schedule(interval=timedelta(minutes=30))
def health_check(self) -> None:
"""Registered as Celery Beat periodic task — runs every 30 minutes."""
...
@schedule(at=time(3, 0))
def daily_cleanup(self) -> None:
"""Runs daily at 03:00."""
...
@schedule(crontab=Crontab(weekday=Weekday.MONDAY, hour=9))
def weekly_report(self) -> None:
"""Runs every Monday at 09:00."""
...
2. Bootstrap the application
from spakky.core.application.application import SpakkyApplication
from spakky.core.application.application_context import ApplicationContext
import spakky.plugins.celery
app = (
SpakkyApplication(ApplicationContext())
.load_plugins(include={spakky.plugins.celery.PLUGIN_NAME})
.scan()
.start()
)
3. Call task methods normally
handler = app.container.get(EmailTaskHandler)
# Dispatched to broker — AOP intercepts and calls send_task()
handler.send_email("user@example.com", "Hello", "World")
The AOP aspect intercepts the calls and routes them to Celery automatically.
Dispatch Behavior
| Decorator | Behavior | Celery API |
|---|---|---|
@task |
Dispatch to broker on each call | send_task() |
@schedule |
Register in Celery Beat | beat_schedule |
Components
| Component | Description |
|---|---|
CeleryConfig |
Configuration loaded from environment variables |
CeleryPostProcessor |
Scans @TaskHandler pods and registers methods as Celery tasks/schedules |
CeleryTaskDispatchAspect |
AOP aspect intercepting sync @task calls |
AsyncCeleryTaskDispatchAspect |
AOP aspect intercepting async @task calls |
Errors
| Error | Description |
|---|---|
InvalidScheduleRouteError |
ScheduleRoute has no valid schedule specification |
Related Packages
spakky-task: Core task abstractions (@TaskHandler,@task,@schedule,Crontab)spakky-rabbitmq: RabbitMQ event transport (can also be used as Celery broker)
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spakky_celery-6.0.0.tar.gz.
File metadata
- Download URL: spakky_celery-6.0.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b05ce6b94e0224d56533fbdf02890d6e4d9edccc717477b68e5892928c06970
|
|
| MD5 |
13693de49847531709a0077965e47e62
|
|
| BLAKE2b-256 |
002f62a6e13c7f7374fec0785f6caf30a3131e3b004cfa32d83d967ca5216d8e
|
Provenance
The following attestation bundles were made for spakky_celery-6.0.0.tar.gz:
Publisher:
publish-package.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_celery-6.0.0.tar.gz -
Subject digest:
7b05ce6b94e0224d56533fbdf02890d6e4d9edccc717477b68e5892928c06970 - Sigstore transparency entry: 1110083799
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@c72d9ed481523a919c2a298454730dd87352010a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@c72d9ed481523a919c2a298454730dd87352010a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_celery-6.0.0-py3-none-any.whl.
File metadata
- Download URL: spakky_celery-6.0.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
859069782cc1c27d10fadd75983ced551b3474d1d8741a473a1fa704a844ea6e
|
|
| MD5 |
9ab741c1c6a67bd3f63b91d6865925e3
|
|
| BLAKE2b-256 |
6a92be6b4db1afb91cff4478fcc4988caafb02e1d2f9e35bf18ccee5b6247cd7
|
Provenance
The following attestation bundles were made for spakky_celery-6.0.0-py3-none-any.whl:
Publisher:
publish-package.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_celery-6.0.0-py3-none-any.whl -
Subject digest:
859069782cc1c27d10fadd75983ced551b3474d1d8741a473a1fa704a844ea6e - Sigstore transparency entry: 1110083800
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@c72d9ed481523a919c2a298454730dd87352010a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@c72d9ed481523a919c2a298454730dd87352010a -
Trigger Event:
workflow_dispatch
-
Statement type: