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
impl JobStore
Sourcepub fn new(pool: DbPool) -> Self
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.
Sourcepub async fn open(path: &str) -> Result<Self, SchedulerError>
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.
Sourcepub async fn init(&self) -> Result<(), SchedulerError>
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.
Sourcepub async fn upsert_job(
&self,
name: &str,
cron_expr: &str,
kind: &str,
) -> Result<(), SchedulerError>
pub async fn upsert_job( &self, name: &str, cron_expr: &str, kind: &str, ) -> Result<(), SchedulerError>
Sourcepub 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>
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.
Sourcepub async fn insert_job(
&self,
name: &str,
cron_expr: &str,
kind: &str,
task_mode: &str,
run_at: Option<&str>,
task_data: &str,
) -> Result<(), SchedulerError>
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.
Sourcepub async fn record_run(
&self,
name: &str,
timestamp: &str,
next_run: &str,
) -> Result<(), SchedulerError>
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.
Sourcepub async fn delete_job(&self, name: &str) -> Result<bool, SchedulerError>
pub async fn delete_job(&self, name: &str) -> Result<bool, SchedulerError>
Sourcepub async fn job_exists(&self, name: &str) -> Result<bool, SchedulerError>
pub async fn job_exists(&self, name: &str) -> Result<bool, SchedulerError>
Sourcepub async fn set_next_run(
&self,
name: &str,
next_run: &str,
) -> Result<(), SchedulerError>
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.
Sourcepub async fn get_next_run(
&self,
name: &str,
) -> Result<Option<String>, SchedulerError>
pub async fn get_next_run( &self, name: &str, ) -> Result<Option<String>, SchedulerError>
Sourcepub async fn list_jobs(
&self,
) -> Result<Vec<ScheduledTaskRecord>, SchedulerError>
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.
Sourcepub async fn list_jobs_full(
&self,
) -> Result<Vec<ScheduledTaskInfo>, SchedulerError>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JobStore
impl !RefUnwindSafe for JobStore
impl Send for JobStore
impl Sync for JobStore
impl Unpin for JobStore
impl UnsafeUnpin for JobStore
impl !UnwindSafe for JobStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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