Task queue abstraction for Spakky Framework (@TaskHandler, @task)
Project description
spakky-task
Task queue abstraction layer for Spakky Framework.
Installation
pip install spakky-task
Features
@TaskHandlerstereotype: Marks classes as task handler pods@taskdecorator: Marks methods as on-demand dispatchable tasks@scheduledecorator: Marks methods for periodic execution (interval, daily, crontab)Crontabvalue object: Python-native cron specification withWeekday/Monthenums- Post-processor: Automatically scans and registers task routes from
@TaskHandlerpods - Implementation-agnostic: Works with any task queue backend (Celery, etc.) via plugins
Usage
On-Demand Tasks
@task marks methods for on-demand dispatch. The backend plugin (e.g., spakky-celery)
intercepts calls via AOP and routes them to the task queue.
from spakky.task import TaskHandler, task
@TaskHandler()
class EmailTaskHandler:
@task
def send_email(self, to: str, subject: str, body: str) -> None:
"""Dispatched to the task queue when called."""
...
Scheduled Tasks
@schedule marks methods for periodic execution. Exactly one of interval, at, or crontab
must be specified.
from datetime import time, timedelta
from spakky.task import TaskHandler, Crontab, Weekday, schedule
@TaskHandler()
class MaintenanceHandler:
@schedule(interval=timedelta(minutes=30))
def health_check(self) -> None:
"""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."""
...
Crontab Specification
Crontab uses Python-native types instead of cron strings. None means "every" (wildcard).
from spakky.task import Crontab, Weekday, Month
# Every Monday at 03:00
Crontab(weekday=Weekday.MONDAY, hour=3)
# Mon/Wed/Fri at 09:00
Crontab(weekday=(Weekday.MONDAY, Weekday.WEDNESDAY, Weekday.FRIDAY), hour=9)
# 1st and 15th of every month at midnight
Crontab(day=(1, 15))
# Every January 1st at midnight
Crontab(month=Month.JANUARY, day=1)
Field order (descending temporal granularity):
| Field | Type | Default |
|---|---|---|
month |
Month | tuple[Month, ...] | None |
None (every) |
day |
int | tuple[int, ...] | None |
None (every) |
weekday |
Weekday | tuple[Weekday, ...] | None |
None (every) |
hour |
int |
0 |
minute |
int |
0 |
Accessing Task Routes
from spakky.task import TaskRegistrationPostProcessor
post_processor = container.get(TaskRegistrationPostProcessor)
routes = post_processor.get_task_routes()
# {<bound method send_email>: TaskRoute(), ...}
Components
| Component | Description |
|---|---|
TaskHandler |
Stereotype decorator for task handler classes |
@task |
Method decorator for on-demand task dispatch |
@schedule |
Method decorator for periodic execution (interval, at, crontab) |
TaskRoute |
Annotation for @task methods |
ScheduleRoute |
Annotation for @schedule methods |
Crontab |
Frozen dataclass for cron-like schedule specification |
Weekday |
IntEnum for day of the week (Monday=0 ... Sunday=6) |
Month |
IntEnum for month of the year (January=1 ... December=12) |
TaskRegistrationPostProcessor |
Scans @TaskHandler pods and collects @task methods |
Errors
| Error | Description |
|---|---|
TaskNotFoundError |
Task reference not found in the registry |
DuplicateTaskError |
Attempting to register an already-registered task |
InvalidScheduleSpecificationError |
@schedule called with zero or multiple schedule options |
Related Packages
spakky-celery: Celery backend for task dispatch and schedule registration via AOP
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_task-6.3.0.tar.gz.
File metadata
- Download URL: spakky_task-6.3.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2f2bd32f969d830415b5d502dcf23c4a4416c16593b593ecf39fd90c2f633c3
|
|
| MD5 |
71e6b98d8408d11ef9f2119d8a2b4c5e
|
|
| BLAKE2b-256 |
659c5c378a14ac06778c78dbb43b27f7adc909f88a41403aa82ecf11f14ccde7
|
Provenance
The following attestation bundles were made for spakky_task-6.3.0.tar.gz:
Publisher:
release.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_task-6.3.0.tar.gz -
Subject digest:
f2f2bd32f969d830415b5d502dcf23c4a4416c16593b593ecf39fd90c2f633c3 - Sigstore transparency entry: 1236423475
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@8ffa826fd763ee2c1408b33c20b785b00bed60b9 -
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:
release.yml@8ffa826fd763ee2c1408b33c20b785b00bed60b9 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_task-6.3.0-py3-none-any.whl.
File metadata
- Download URL: spakky_task-6.3.0-py3-none-any.whl
- Upload date:
- Size: 9.4 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 |
c83fe9a6a57c405d40149b456e3f4821908c6660562087eed3a5ff5e53f1f219
|
|
| MD5 |
7fc96b78d13d9e9d00a4f7ae89284f20
|
|
| BLAKE2b-256 |
edc5df4dae486cbde8a33052bd55f0ddd6299a9b1351afc5fd1062258c6bc6b3
|
Provenance
The following attestation bundles were made for spakky_task-6.3.0-py3-none-any.whl:
Publisher:
release.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_task-6.3.0-py3-none-any.whl -
Subject digest:
c83fe9a6a57c405d40149b456e3f4821908c6660562087eed3a5ff5e53f1f219 - Sigstore transparency entry: 1236423527
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@8ffa826fd763ee2c1408b33c20b785b00bed60b9 -
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:
release.yml@8ffa826fd763ee2c1408b33c20b785b00bed60b9 -
Trigger Event:
workflow_dispatch
-
Statement type: