Tempus
Tempus Julia package repo.
Tempus.Tempus — ModuleTempus provides a cron-style job scheduling framework for Julia, inspired by Quartz in Java.
Features:
- Define jobs with cron-like scheduling expressions
- Supports job execution policies (overlap handling, retries, and failure strategies)
- Multiple job stores and JobStore interface (in-memory, file-based persistence)
- Concurrency-aware execution with configurable retry logic
- Supports disabling, enabling, and unscheduling jobs dynamically
- Thread-safe scheduling with a background execution loop
Tempus.FileStore — TypeFileStore <: StoreA file-based job storage backend that persists jobs to disk as JSON. Job execution history is only kept in memory (not persisted).
Fields:
filepath::String: The file path where jobs are stored as JSON.store::InMemoryStore: In-memory store that handles operations before syncing to disk.
Tempus.InMemoryStore — TypeInMemoryStore <: StoreAn in-memory job storage backend.
Fields:
jobs::Set{Job}: Stores active jobs.jobExecutions::Dict{String, Vector{JobExecution}}: Stores execution history for each job.
Tempus.Job — TypeJobRepresents a single job/unit of work. Can be scheduled to repeat.
Fields:
name::String: Unique identifier for the job.schedule::Union{Cron, Nothing}: The cron-style schedule expression.action::Function: The function to execute when the job runs.action_ref::Union{Nothing, String}: Fully qualified function reference for persistence (e.g."MyModule.my_handler").action_data::Union{Nothing, String}: JSON-encoded parameters for persistence. Splatted as kwargs:action(; JSON.parse(action_data)...).options::JobOptions: Execution options for retries, failures, and overlap handling.disabledAt::Union{DateTime, Nothing}: Timestamp when the job was disabled (if applicable).
Tempus.JobExecution — TypeJobExecutionRepresents an instance of a job execution.
Fields:
jobExecutionId::String: Unique identifier for this job execution.job::Job: The job being executed.scheduledStart::DateTime: When the job was scheduled to run.runConcurrently::Bool: Whether this execution is running concurrently with another.actualStart::DateTime: The actual start time.finish::DateTime: The completion time.status::Symbol: The execution result (:succeeded,:failed).
Tempus.JobOptions — TypeJobOptionsDefines options for job execution behavior.
Fields:
overlap_policy::Union{Symbol, Nothing}: Determines job execution behavior when the same job is already running (:skip,:queue,:concurrent).retries::Int: Number of retries allowed on failure.retry_delays::Union{Base.ExponentialBackOff, Nothing}: Delay strategy for retries (defaults to exponential backoff ifretries > 0).retry_check: Custom function to determine retry behavior (checkargument fromBase.retry).max_failed_executions::Union{Int, Nothing}: Maximum number of failed executions allowed for a job before it will be disabled.max_executions::Union{Int, Nothing}: Maximum number of executions allowed for a job.expires_at::Union{DateTime, Nothing}: Expiration time for a job.timezone::Union{Nothing, String}: IANA timezone name (e.g."America/Denver"). When set, the job's cron schedule is interpreted in this timezone.nothingmeans UTC.
Tempus.SQLiteStore — TypeSQLiteStore <: StoreA SQLite-backed job storage that uses an InMemoryStore as cache. The db field holds the SQLite.DB (typed as Any to avoid hard dependency). The extension TempusSQLiteExt provides the constructor and all store methods.
Tempus.Scheduler — TypeSchedulerThe main scheduling engine that executes jobs according to their schedules.
Fields:
lock::ReentrantLock: Ensures thread-safe access.jobExecutions::Vector{JobExecution}: List of scheduled job executions.store::Store: Job storage backend.jobExecutionFinished::Threads.Event: Signals all job executions have finished when shutting down.executingJobExecutions::Set{JobExecution}: Tracks currently executing jobs.running::Bool: Scheduler state (running/stopped).jobOptions::JobOptions: Default job execution options.max_concurrent_executions::Int: Limit on how many total executions can be running concurrently for this scheduler, defaults toThreads.nthreads()logging::Bool: Whether to emit log messages during scheduler operations, defaults totrue.
Tempus.Store — TypeStoreDefines an interface for job storage backends.
Base.close — Methodclose(scheduler::Scheduler)Closes the scheduler, stopping job execution; waits for any currently executing jobs to finish. Will wait timeout seconds (5 by default) for any currently executing jobs to finish before returning.
Base.push! — Methodpush!(scheduler::Scheduler, job::Job)Adds a job to the scheduler and underlying Store, scheduling its next execution based on its cron schedule.
Base.wait — Methodwait(scheduler::Scheduler)Waits for the scheduler to finish executing all jobs. Note the scheduler must be explicitly closed to stop the scheduler loop or pass close_when_no_jobs=true to run! to automatically close the scheduler when no jobs are left.
Tempus._function_ref — MethodAuto-extract fully qualified function reference string from a named function.
Tempus.addJob! — FunctionaddJob!(store::Store, job::Job)Add a new job to store.
Tempus.disable! — Methoddisable!(job::Job)Disables a job, preventing it from being scheduled for execution.
Tempus.disableJob! — MethoddisableJob!(store::Store, job::Union{Job, String})Disable a job in store by reference or name.
Tempus.enable! — Methodenable!(job::Job)Enables a previously disabled job, allowing it to be scheduled again.
Tempus.getJobs — FunctiongetJobs(store::Store) -> Collection{Job}Retrieve all jobs stored in store, regardless of disabled status.
Tempus.getNMostRecentJobExecutions — MethodgetNMostRecentJobExecutions(store::Store, jobName::String, n::Int) -> Vector{JobExecution}Get the n most recent job executions for a job persisted in store.
Tempus.getnext — Functiongetnext(cron::Cron, timezone::String, from::DateTime=Dates.now(UTC)) -> DateTimeCompute the next trigger time for cron interpreted in timezone (IANA name, e.g. "America/Denver"). from is a UTC DateTime. Returns a UTC DateTime. DST handling: spring-forward gaps are skipped, fall-back ambiguities use the first occurrence.
Tempus.isdisabled — Methodisdisabled(job::Job) -> BoolReturns true if the job is currently disabled.
Tempus.purgeJob! — FunctionpurgeJob!(store::Store, job::Union{Job, String})Remove a job from store by reference or name. All job execution history will also be removed.
Tempus.resolve_function — Methodresolve_function(ref::String) -> FunctionResolve a function from its fully qualified reference string (e.g. "MyModule.my_handler"). The module must be loaded before calling this function.
Tempus.run! — Methodrun!(scheduler::Scheduler)Starts the scheduler, executing jobs at their scheduled times.
Tempus.runJobs! — MethodrunJobs!(store::Store, jobs; kw...)Add each job in jobs to store, run a scheduler with kw options, wait for all jobs to finish, then close the scheduler.
Tempus.storeJobExecution! — MethodstoreJobExecution!(store::Store, jobExecution::JobExecution)Store jobExecution in store.
Tempus.withscheduler — Methodwithscheduler(f, args...; kw...)Creates a scheduler, runs a function f with it, then calls close.