pub struct Schedule { /* private fields */ }Expand description
A set of recurring tasks, declared once (typically inline in the
generated app’s own schedule:work branch - see docs/ARCHITECTURE.md’s
“Scheduler” section) and handed to work. Consuming, Self-returning
builder - the same “build a registry, then run it” shape as
larust_queue::JobRegistry.
Implementations§
Source§impl Schedule
impl Schedule
pub fn new() -> Schedule
Sourcepub fn cron<F, Fut>(self, expr: &str, task: F) -> Schedule
pub fn cron<F, Fut>(self, expr: &str, task: F) -> Schedule
Escape hatch for any frequency the fluent methods below don’t cover
directly (e.g. "0 */5 * * * * *" for every 5 minutes). Uses the
cron crate’s own 7-field extended dialect - seconds, minutes,
hours, day-of-month, month, day-of-week, year - not Laravel’s
classic 5-field Unix cron format.
Panics on an invalid expression: this is a startup-time
configuration mistake, not a runtime condition - the same
fail-loud-immediately precedent larust_queue::JobRegistry:: register’s duplicate-JOB_TYPE panic already establishes, rather
than surfacing as a confusing “the scheduler silently never runs
this task” bug discovered much later.
Sourcepub fn name(self, name: impl Into<String>) -> Schedule
pub fn name(self, name: impl Into<String>) -> Schedule
Names the most recently registered task - same “applies to
whatever was just registered” convention larust_http::Router:: name already uses for routes. Required before
Self::on_one_server: a task closure has no identity of its own
to derive a stable cross-process lock key from (unlike
larust_queue::Job::JOB_TYPE, a compile-time constant on a real
type) - matching Laravel’s own requirement that a closure-based
scheduled task be named before ->onOneServer() can be used.
§Panics
If called before registering any task at all.
Sourcepub fn on_one_server(self) -> Schedule
pub fn on_one_server(self) -> Schedule
Marks the most recently registered task so at most one xr schedule:work process actually runs it for each due occurrence,
even when multiple processes are running against the same app
(e.g. a rolling deploy’s brief overlap) - Laravel’s own
->onOneServer(). Backed by a small self-bootstrapping
scheduler_locks table (no migration file, same lazy CREATE TABLE IF NOT EXISTS idiom larust-notifications’s ensure_table
establishes): the first process whose claim attempt for a given
(task name, due instant) pair wins an INSERT actually runs the
task; every other process racing for the same pair loses the
INSERT to a unique-constraint violation and skips it - the same
“claim by winning a race-safe write, treat losing as a normal
no-op” shape larust_queue::sql_worker::claim_next already uses
for job claiming, not an advisory-lock/session-primitive approach
(SQLite has no equivalent to Postgres’s pg_advisory_lock/MySQL’s
GET_LOCK() at all, so a plain row claim is the only mechanism
portable across every backend this framework supports).
A task NOT marked this way keeps today’s original behavior unchanged: whichever process’s own tick lands on a due instant just runs it, no coordination, no database dependency added - still correct for a genuinely single-process deployment, which remains the default.
A claim-attempt database error is treated as “don’t run this occurrence,” not “run it anyway”: the documented failure mode this mechanism exists to prevent (silent duplicate side effects) is worse than an occasional missed run under a database outage.
§Panics
If the most recently registered task has no name yet (see
Self::name) - the same fail-loud-at-registration-time
precedent every other Schedule builder method already
establishes for a startup-time configuration mistake.
Sourcepub fn every_minute<F, Fut>(self, task: F) -> Schedule
pub fn every_minute<F, Fut>(self, task: F) -> Schedule
Runs task once every minute, at second 0.
Sourcepub fn daily_at<F, Fut>(self, time: &str, task: F) -> Schedule
pub fn daily_at<F, Fut>(self, time: &str, task: F) -> Schedule
Runs task once a day at the given "HH:MM" UTC time. Panics on a
malformed or out-of-range value - same fail-loud-at-startup
precedent as Self::cron’s invalid-expression panic.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Schedule
impl !UnwindSafe for Schedule
impl Forget for Schedule
impl Freeze for Schedule
impl Move for Schedule
impl Send for Schedule
impl Sync for Schedule
impl Unpin for Schedule
impl UnsafeUnpin for Schedule
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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