Task Registration Contract
This document describes the atomic registration contract for scheduled tasks in the Oridecon tasks framework.
Decorators
Section titled “Decorators”@task(name)
Section titled “@task(name)”Registers a handler for on-demand task execution. The decorated callable is
boot-discovered when its module is imported through
TasksModule.configure(task_modules=[...]) or task_packages=[...].
from oridecon.tasks.decorators import task
@task(name="send-email")async def send_email(to: str, subject: str, body: str) -> None: ...@scheduled(cron, name)
Section titled “@scheduled(cron, name)”Registers a handler for both on-demand execution and scheduled execution.
Requires both _task_name and _cron attributes. During provider boot the
framework imports the configured task module/package roots, auto-registers the
handler, and adds its cron job to the scheduler.
from oridecon.tasks.decorators import scheduled
@scheduled(cron="*/5 * * * *", name="cleanup-expired")async def cleanup_expired() -> None: ...Atomicity Guarantee
Section titled “Atomicity Guarantee”The TaskProvider.register_scheduled_task() method provides an atomic registration contract:
- Validation — If the task lacks
_task_nameor_cron,TaskRegistrationErroris raised immediately - Registration — The handler is registered with the registry
- Scheduling — If scheduling fails, the registration is rolled back via
unregister()
Invariant: A task is in the schedule if and only if it is in the registry.
Error Handling
Section titled “Error Handling”TaskRegistrationError
Section titled “TaskRegistrationError”Raised when task registration fails due to missing metadata:
- Missing
_task_name: The@scheduleddecorator was not applied correctly - Missing
_cron: Use@task()for non-scheduled handlers
Example:
TaskRegistrationError: register_scheduled_task: object <function my_task at 0x...> lacks _task_name (was @scheduled decorator applied correctly?)Recovery
Section titled “Recovery”If a scheduled task fails to register, the application refuses to boot. This is intentional — a misconfigured task indicates a wiring error that should be caught at startup, not left to fail silently in the DLQ.
To fix:
- Verify the
@scheduleddecorator is applied correctly - Ensure the task function has both
nameandcronparameters - Ensure the module is included in
TasksModule.configure(task_modules=[...])or lives under a configuredtask_packages=[...]root