task to decorate application work. It returns a TaskCallable whose direct call runs inline and whose defer method submits queued work. The returned TaskHandle exposes status, cancellation, and result access.
For discovery, storage setup, and durable waiting, see Create and run Tasks, Task and cron storage, and Durable execution.
Task parameters
idempotency_key and schedule_in are options on .defer(); avoid using them as task input names. Arguments and results must be strict JSON values: no credentials, arbitrary Python objects, non-string object keys, or non-finite numbers. Workers may retry, so task side effects must be idempotent.
Handle behavior
.defer() without an active compiled runtime raises TaskUnavailableError; calling the decorated function directly does not require queue storage.
TaskStore and TaskRecord are storage adapter contracts. TaskDefinition and CompiledTask describe compiler/runtime registrations. Use Task and cron storage to choose a production provider; MemoryTaskStore does not make work survive a process restart.
Storage protocols
Exports
CompiledTask
One compiler-named task executable in the compiled application runtime.— means no declared default):
Parameters and example
Parameters and example
CompiledTask.function
Return the original callable only at the trusted worker boundary.Example
Example
CompiledTask.queue
Return the authored queue without exposing the definition object.Example
Example
CompiledTask.max_retries
Return the bounded retry count used during native registration.Example
Example
MemoryTaskStore
Implement atomic contracts in one process; records do not survive restart.Example
Example
MemoryTaskStore.start
Example
Example
MemoryTaskStore.close
Example
Example
MemoryTaskStore.enqueue_task
Parameters and example
Parameters and example
MemoryTaskStore.get_task
Parameters and example
Parameters and example
MemoryTaskStore.list_task_metadata
Parameters and example
Parameters and example
MemoryTaskStore.claim_tasks
Parameters and example
Parameters and example
MemoryTaskStore.renew_task_lease
Parameters and example
Parameters and example
MemoryTaskStore.finish_task
Parameters and example
Parameters and example
MemoryTaskStore.cancel_task
Parameters and example
Parameters and example
MemoryTaskStore.create_cron
Parameters and example
Parameters and example
MemoryTaskStore.get_cron
Parameters and example
Parameters and example
MemoryTaskStore.list_crons
Parameters and example
Parameters and example
MemoryTaskStore.list_cron_metadata
Parameters and example
Parameters and example
MemoryTaskStore.update_cron
Parameters and example
Parameters and example
MemoryTaskStore.delete_cron
Parameters and example
Parameters and example
MemoryTaskStore.list_due_crons
Parameters and example
Parameters and example
MemoryTaskStore.commit_cron_occurrence
Parameters and example
Parameters and example
PostgresTaskStore
Persist jobs and schedules with transactional claims and fenced leases._pool supports composing this provider with the combined session store;
externally supplied pools remain owned by their caller.
Parameters and example
Parameters and example
PostgresTaskStore.start
Example
Example
PostgresTaskStore.close
Example
Example
PostgresTaskStore.create_cron
Parameters and example
Parameters and example
PostgresTaskStore.get_cron
Parameters and example
Parameters and example
PostgresTaskStore.list_crons
Parameters and example
Parameters and example
PostgresTaskStore.update_cron
Parameters and example
Parameters and example
PostgresTaskStore.delete_cron
Parameters and example
Parameters and example
PostgresTaskStore.list_due_crons
Parameters and example
Parameters and example
PostgresTaskStore.commit_cron_occurrence
Parameters and example
Parameters and example
PostgresTaskStore.enqueue_task
Parameters and example
Parameters and example
PostgresTaskStore.get_task
Parameters and example
Parameters and example
PostgresTaskStore.claim_tasks
Parameters and example
Parameters and example
PostgresTaskStore.renew_task_lease
Parameters and example
Parameters and example
PostgresTaskStore.finish_task
Parameters and example
Parameters and example
PostgresTaskStore.cancel_task
Parameters and example
Parameters and example
PostgresTaskStore.list_task_metadata
Parameters and example
Parameters and example
PostgresTaskStore.list_cron_metadata
Parameters and example
Parameters and example
TaskCallable
Preserve direct invocation while adding an asynchronous defer boundary.Parameters and example
Parameters and example
TaskCallable.call
Parameters and example
Parameters and example
TaskCallable.defer
Parameters and example
Parameters and example
TaskDefinition
Authoring metadata retained on a decorated function.— means no declared default):
Parameters and example
Parameters and example
TaskHandle
Opaque queue handle returned after a job is committed. Obtain this object from the owning Harnest API; its constructor includes runtime bindings. Fields (— means no declared default):
Example
Example
TaskHandle.status
Example
Example
TaskHandle.cancel
Example
Example
TaskHandle.result
Example
Example
TaskRecord
Private persisted job, including reconstructable invocation capabilities. Epoch timestamps are UTC seconds. Attempts count claims, starting at one;max_retries permits that many attempts after the first. Providers retain
an immutable enqueue fingerprint after clearing terminal private payloads.
— means no declared default):
Parameters and example
Parameters and example
TaskStore
Atomic operations required for at-least-once task execution. All selection, scope predicates, ordering, and limits execute inside the datastore. A provider must durably commit before returning success. Expired lease holders cannot renew or finish work. Terminal transitions clear arguments, invocation and permissions while retaining the result/failure.Example
Example
TaskStore.start
Example
Example
TaskStore.close
Example
Example
TaskStore.enqueue_task
Parameters and example
Parameters and example
TaskStore.get_task
Parameters and example
Parameters and example
TaskStore.claim_tasks
Parameters and example
Parameters and example
TaskStore.renew_task_lease
Parameters and example
Parameters and example
TaskStore.finish_task
Parameters and example
Parameters and example
TaskStore.cancel_task
Parameters and example
Parameters and example
TaskStoreConflictError
A stable job identity or idempotency key has a different definition.Example
Example
TaskUnavailableError
A task was deferred without its compiled runtime being active.Example
Example
safe_task_result
Normalize a task result to the strict JSON values safe for persistence.Parameters and example
Parameters and example
task
Mark a callable for queue, scheduling, and retry execution. Deferred execution uses Harnest workers and the application’s configuredlifecycle.storage.tasks provider. Durable storage makes queued work
recoverable across restarts; importing this API requires no queue library.
Direct calls remain ordinary Python calls; defer is queue execution and
never promises restoration of a suspended Python frame.
Parameters and example
Parameters and example