Skip to main content

JobStore

Struct JobStore 

Source
pub struct JobStore { /* private fields */ }
Expand description

Persistent storage layer for scheduled jobs.

All job definitions and run history are stored in a SQLite database managed by zeph-db migrations. The scheduled_jobs table schema is defined in migration 051_scheduler_jobs.sql.

§Examples

use zeph_scheduler::JobStore;

// Open from a file path.
let store = JobStore::open("sqlite:scheduler.db").await?;
store.init().await?;

// Query job list.
let jobs = store.list_jobs().await?;
for job in &jobs {
    println!("{}: {} ({}) → {}", job.name, job.kind, job.task_mode, job.next_run);
}

Implementations§

Source§

impl JobStore

Source

pub fn new(pool: DbPool) -> Self

Create a JobStore from an existing zeph_db::DbPool.

You must call JobStore::init before any other operation to ensure the schema migrations have been applied.

Source

pub async fn open(path: &str) -> Result<Self, SchedulerError>

Open (or create) a JobStore from a SQLite file path.

§Errors

Returns SchedulerError::Db if the connection cannot be established.

Source

pub async fn init(&self) -> Result<(), SchedulerError>

Run all pending migrations on the underlying pool.

Replaces the former inline CREATE TABLE IF NOT EXISTS DDL. The scheduled_jobs schema is now managed by migration 051_scheduler_jobs.sql in zeph-db.

§Errors

Returns an error if any migration fails.

Source

pub async fn upsert_job( &self, name: &str, cron_expr: &str, kind: &str, ) -> Result<(), SchedulerError>

Upsert a job definition.

§Errors

Returns an error if the SQL statement fails.

Source

pub async fn upsert_job_with_mode( &self, name: &str, cron_expr: &str, kind: &str, task_mode: &str, run_at: Option<&str>, task_data: &str, ) -> Result<(), SchedulerError>

Upsert a job definition with explicit task_mode, optional run_at, and task_data.

§Errors

Returns an error if the SQL statement fails.

Source

pub async fn insert_job( &self, name: &str, cron_expr: &str, kind: &str, task_mode: &str, run_at: Option<&str>, task_data: &str, ) -> Result<(), SchedulerError>

Insert a new job. Returns SchedulerError::DuplicateJob if a job with this name exists.

§Errors

Returns SchedulerError::DuplicateJob on unique constraint violation, or SchedulerError::Database on other SQL errors.

Source

pub async fn record_run( &self, name: &str, timestamp: &str, next_run: &str, ) -> Result<(), SchedulerError>

Record a job execution and persist the next scheduled run time.

§Errors

Returns an error if the SQL statement fails.

Source

pub async fn mark_done(&self, name: &str) -> Result<(), SchedulerError>

Mark a one-shot job as done.

§Errors

Returns an error if the SQL statement fails.

Source

pub async fn delete_job(&self, name: &str) -> Result<bool, SchedulerError>

Delete a job by name.

§Errors

Returns an error if the SQL statement fails.

Source

pub async fn job_exists(&self, name: &str) -> Result<bool, SchedulerError>

Check if a job with the given name exists.

§Errors

Returns an error if the SQL query fails.

Source

pub async fn set_next_run( &self, name: &str, next_run: &str, ) -> Result<(), SchedulerError>

Persist the next scheduled run time for a job (used during init).

§Errors

Returns an error if the SQL statement fails.

Source

pub async fn get_next_run( &self, name: &str, ) -> Result<Option<String>, SchedulerError>

Get the persisted next run timestamp for a job.

§Errors

Returns an error if the SQL query fails.

Source

pub async fn list_jobs( &self, ) -> Result<Vec<ScheduledTaskRecord>, SchedulerError>

List all active (non-done) jobs.

Returns a ScheduledTaskRecord per active job, ordered by name. One-shot jobs without a computed next_run fall back to their run_at value; if neither is set the field is an empty string.

§Errors

Returns an error if the SQL query fails.

Source

pub async fn list_jobs_full( &self, ) -> Result<Vec<ScheduledTaskInfo>, SchedulerError>

List all active (non-done) jobs with full details for display.

§Errors

Returns an error if the SQL query fails.

Source

pub fn pool(&self) -> &DbPool

Returns a reference to the underlying connection pool.

Primarily used in tests that need to execute raw SQL against the same database.

Trait Implementations§

Source§

impl Debug for JobStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more