spakky-task¶
태스크 추상화 — 스케줄링, 디스패치
Stereotype¶
spakky.task.stereotype.task_handler
¶
TaskHandler stereotype and task routing decorators.
This module provides @TaskHandler stereotype and @task decorator for organizing task-queue-driven architectures.
TaskRoute()
dataclass
¶
Bases: FunctionAnnotation
Annotation for marking methods as dispatchable tasks.
Associates a method as a task that can be dispatched to a task queue.
TaskHandler(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for task handler classes.
TaskHandlers contain methods decorated with @task that can be dispatched to task queues asynchronously.
task(obj)
¶
Decorator for marking methods as dispatchable tasks.
All @task methods are dispatched to the task queue by the plugin aspect.
Example
@TaskHandler() class EmailTaskHandler: @task def send_email(self, to: str, subject: str, body: str) -> None: ...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Callable[P, T]
|
The method to mark as a task. |
required |
Returns:
| Type | Description |
|---|---|
Callable[P, T]
|
The annotated method. |
Source code in core/spakky-task/src/spakky/task/stereotype/task_handler.py
options: show_root_heading: false
spakky.task.stereotype.schedule
¶
Schedule stereotype for periodic task execution.
Provides @schedule decorator to mark TaskHandler methods for periodic execution (interval, daily, or crontab-based).
ScheduleRoute(interval=None, at=None, crontab=None)
dataclass
¶
Bases: FunctionAnnotation
Annotation for marking methods as periodically scheduled tasks.
Exactly one of interval, at, or crontab must be provided.
schedule(*, interval=None, at=None, crontab=None)
¶
Decorator for marking methods as periodically scheduled tasks.
Exactly one of interval, at, or crontab must be specified.
Example
@TaskHandler() class MaintenanceHandler: @schedule(interval=timedelta(minutes=30)) def health_check(self) -> None: ...
@schedule(at=time(3, 0))
def daily_cleanup(self) -> None:
...
@schedule(crontab=Crontab(hour=9, weekday=(Weekday.MONDAY, Weekday.WEDNESDAY, Weekday.FRIDAY)))
def triweekly_report(self) -> None:
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
timedelta | None
|
Fixed interval between executions. |
None
|
at
|
time | None
|
Daily execution at a specific time. |
None
|
crontab
|
Crontab | None
|
Cron-like schedule specification. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[P, T]], Callable[P, T]]
|
A decorator that annotates the method with ScheduleRoute. |
Source code in core/spakky-task/src/spakky/task/stereotype/schedule.py
options: show_root_heading: false
spakky.task.stereotype.crontab
¶
Crontab value object for schedule specification.
Weekday
¶
Bases: IntEnum
Day of the week (ISO 8601: Monday=0).
Month
¶
Bases: IntEnum
Month of the year (1-12).
Crontab(month=None, day=None, weekday=None, hour=0, minute=0)
dataclass
¶
Cron-like schedule specification using Python native types.
Fields use None to mean "every" (wildcard).
A single int means exactly that value; a tuple means multiple values.
Example
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))
month = None
class-attribute
instance-attribute
¶
Month of the year. None means every month.
day = None
class-attribute
instance-attribute
¶
Day of the month (1-31). None means every day.
weekday = None
class-attribute
instance-attribute
¶
Day of the week. None means every day.
hour = 0
class-attribute
instance-attribute
¶
Hour of the day (0-23).
minute = 0
class-attribute
instance-attribute
¶
Minute of the hour (0-59).
options: show_root_heading: false
Interfaces¶
spakky.task.interfaces.task_result
¶
Abstract task result handle for background task dispatchers.
AbstractTaskResult
¶
Bases: ABC, Generic[T]
Abstract handle for the result of a dispatched background task.
Concrete adapters (e.g. CeleryTaskResult) implement this for each broker.
options: show_root_heading: false
Post Processor¶
spakky.task.post_processor
¶
Task handler registration post-processor.
TaskRegistrationPostProcessor()
¶
Bases: IPostProcessor
Post-processor that scans @TaskHandler pods for @task methods.
This post-processor collects all task routes from TaskHandler pods and makes them available for task queue implementations to register.
Source code in core/spakky-task/src/spakky/task/post_processor.py
post_process(pod)
¶
Scan pod for @task methods and register their routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The pod instance to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The unmodified pod instance. |
Source code in core/spakky-task/src/spakky/task/post_processor.py
options: show_root_heading: false
Errors¶
spakky.task.error
¶
options: show_root_heading: false