pub struct App { /* private fields */ }Expand description
The main application builder for Celerix.
Provides a minimal API to register HTTP routes (via axum), queue consumers, and scheduled tasks — all targeting Cloudflare Workers.
Implementations§
Source§impl App
impl App
Sourcepub fn router(&mut self, router: Router) -> &mut App
pub fn router(&mut self, router: Router) -> &mut App
Merge a full axum Router (for advanced use-cases / nesting).
Sourcepub fn nest(&mut self, path: &str, router: Router) -> &mut App
pub fn nest(&mut self, path: &str, router: Router) -> &mut App
Nest a router under a prefix path.
Sourcepub fn queue<H>(&mut self, queue_name: &str, handler: H) -> &mut Appwhere
H: QueueHandler,
pub fn queue<H>(&mut self, queue_name: &str, handler: H) -> &mut Appwhere
H: QueueHandler,
Register a raw queue consumer for the given queue name.
Sourcepub fn schedule<F, Fut>(&mut self, handler: F) -> ScheduleBuilder<'_>
pub fn schedule<F, Fut>(&mut self, handler: F) -> ScheduleBuilder<'_>
Register a scheduled task. Returns a builder to set the interval.
ⓘ
app.schedule(|| async {
worker::console_log!("runs every 5s");
Ok(())
}).every_five_seconds();
app.schedule(|| async {
worker::console_log!("custom cron");
Ok(())
}).cron("*/5 * * * *");Register a scheduled task. Returns a builder to set the interval.
The closure receives a Ctx with access to queue() and storage().
ⓘ
app.schedule(|ctx| async move {
let count = ctx.storage().get("counter").await?.unwrap_or_default();
info!("counter = {count}");
Ok(())
}).every_minute();Sourcepub fn into_router(self) -> Router
pub fn into_router(self) -> Router
Consume the app and return the built axum Router.
Sourcepub fn queue_handlers(&self) -> &HashMap<String, Box<dyn QueueHandler>>
pub fn queue_handlers(&self) -> &HashMap<String, Box<dyn QueueHandler>>
Get a reference to queue handlers.
Sourcepub fn take_scheduled_tasks(&mut self) -> Vec<ScheduledTask>
pub fn take_scheduled_tasks(&mut self) -> Vec<ScheduledTask>
Take the scheduled tasks.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for App
impl !RefUnwindSafe for App
impl Send for App
impl Sync for App
impl Unpin for App
impl UnsafeUnpin for App
impl !UnwindSafe for App
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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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