Skip to main content

Schedule

Struct Schedule 

Source
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

Source

pub fn new() -> Schedule

Source

pub fn cron<F, Fut>(self, expr: &str, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

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.

Source

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.

Source

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.

Source

pub fn every_minute<F, Fut>(self, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

Runs task once every minute, at second 0.

Source

pub fn hourly<F, Fut>(self, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

Runs task once every hour, on the hour.

Source

pub fn daily<F, Fut>(self, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

Runs task once a day, at midnight UTC.

Source

pub fn daily_at<F, Fut>(self, time: &str, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

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.

Source

pub fn weekly<F, Fut>(self, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

Runs task once a week, Sunday at midnight UTC.

Source

pub fn monthly<F, Fut>(self, task: F) -> Schedule
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AppError>> + Send + 'static,

Runs task once a month, on the 1st at midnight UTC.

Trait Implementations§

Source§

impl Default for Schedule

Source§

fn default() -> Schedule

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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