Skip to main content
All Python modules · Import and compatibility guidance Use Cron for a fixed application-owned declaration. Use create to obtain a CronJob for a user-owned schedule. The module functions and CronJob methods manage dynamic schedules; Cron itself has no pause, resume, or delete methods. For setup and usage, see Cron schedules, Dynamic schedules, and Task and cron storage.

Declare a cron function

@cron(...) creates a queued task for a same-named function in a root cron/<name>.py file. Give the function a docstring. A fixed expression uses the supplied arguments on each occurrence. Omit the expression for dynamic scheduling only; in that form, do not supply arguments or a non-UTC timezone. Do not stack @cron with @task because the decorator creates its own task. Direct calls run inline. queue="default" and max_retries=3 use the Task validation rules.

Schedule parameters

Dynamic schedule behavior

Calls require an active managed invocation and a cron-enabled runtime. Register the same durable provider for tasks and cron. Each operation checks the active application and user; retaining a CronJob does not grant access outside that scope. CronJob is immutable. Assign the returned snapshot, for example job = await job.pause(), or fetch it again to read updated fields. Cancelling or deleting a schedule does not cancel tasks already queued or running. Cancelled schedules cannot be updated, paused, or resumed. CronJob.run_count counts queued occurrences; CronJob.consecutive_failures counts final failed outcomes since the last success. Reaching either configured limit cancels future scheduling.

Errors

CronRecord, CronStore, and CompiledCron are integration contracts. Application tools normally work with CronJob and the module functions.

Exports

CompiledCron

One compiler-resolved schedule with a stable application-owned identity.
Fields (— means no declared default):

CompiledCron.task_name

Return the compiler-owned native task name targeted by the schedule.

Cron

Schedule one discovered task using a strict five-column UTC expression.
Fields (— means no declared default):

CronConflictError

Raised when a schedule key already owns a different definition.

CronJob

One user-owned recurring schedule retained by a running application. Obtain this object from the owning Harnest API; its constructor includes runtime bindings. Fields (— means no declared default):

CronJob.update

Replace supplied fields while preserving this schedule’s identity.

CronJob.pause

Stop future occurrences without deleting the schedule.

CronJob.resume

Resume future occurrences from the next matching UTC minute.

CronJob.cancel

Permanently stop future occurrences while retaining this record.

CronJob.delete

Delete this schedule within the currently active owner scope.

CronNotFoundError

Raised when a user-owned dynamic schedule no longer exists.

CronRecord

Private user-owned schedule with a durable next-occurrence cursor.
Fields (— means no declared default):

CronRuntimeError

Raised when durable cron persistence or dispatch fails safely.

CronStore

Durable CRUD and occurrence handoff on the same provider as TaskStore. User calls always include application and user predicates. Ordered queries and pagination run in the datastore. Cron parsing and next-run calculation belong to Harnest core. Providers enforce revisions and atomic handoff.

CronStore.start

Open provider resources; a shared TaskStore instance starts once.

CronStore.close

Release provider resources after the owning runtime stops dispatch.

CronStore.create_cron

Create, or return exact definition at application/user/key identity. Exact retries return existing paused/cancelled schedules unchanged. Different definitions and conflicting schedule IDs raise conflict.

CronStore.get_cron

Read one owner-scoped schedule without disclosing other owners.

CronStore.list_crons

Return schedules after the ID cursor; limit must be from 1 to 1000.

CronStore.update_cron

Replace mutable fields and increment revision with an atomic CAS. IDs, owner, key and task name are immutable. Cancelled is terminal. An identical cancelled retry returns the existing record unchanged. Missing records raise KeyError; state/revision conflicts raise conflict.

CronStore.delete_cron

Remove only an owner-scoped schedule; missing/foreign returns false.

CronStore.list_due_crons

Page active due schedules by time then ID; limit is from 1 to 1000.

CronStore.commit_cron_occurrence

Atomically enqueue one occurrence and advance the active schedule. Require matching owner, revision and next_run_at==due_at, and a task matching the schedule owner/target/arguments. next_run_at must advance. Stale or inactive returns None with no task insert. Duplicate deliveries cannot create another task. Advance revision within the same transaction.

CronStoreConflictError

A schedule definition, terminal state or expected revision conflicts.

CronUnavailableError

Raised when dynamic schedules are used outside a cron-enabled runtime.

cancel

Permanently stop future occurrences while retaining the job record.

create

Schedule registered work with optional dispatch and failure limits.

cron decorator

Declare a cron function in cron/ with an implicit queued task. Omit the schedule for dynamic scheduling only. The filename and function name must match. Direct calls remain inline; serving registers the task.

delete

Delete one user-owned schedule.

get

Return one schedule owned by the active invocation user.

list

Return a bounded stable page of schedules for the active user.

pause

Pause one user-owned schedule.

resume

Resume one user-owned schedule.

update

Update one user-owned schedule through the active runtime.