pub struct AtrgApp { /* private fields */ }Expand description
The application builder. Accumulates user routers and configuration,
then boots the full server when AtrgApp::run is called.
Implementations§
Source§impl AtrgApp
impl AtrgApp
Sourcepub fn mount(self, router: Router<AppState>) -> Self
pub fn mount(self, router: Router<AppState>) -> Self
Mount an additional [axum::Router] into the application.
Routes are merged, so multiple calls to mount accumulate routes.
Sourcepub fn with_auth_routes(self, router: Router<AppState>) -> Self
pub fn with_auth_routes(self, router: Router<AppState>) -> Self
Sourcepub fn with_cleanup_task<F>(self, f: F) -> Self
pub fn with_cleanup_task<F>(self, f: F) -> Self
Register a background cleanup task that is spawned after the server starts. Typically used for periodic session / OAuth-state expiry.
The callback receives the [DbPool] and is expected to call
tokio::spawn internally.
Sourcepub fn with_db_pool(self, pool: impl Into<DbPool>) -> Self
pub fn with_db_pool(self, pool: impl Into<DbPool>) -> Self
Use a caller-provided database pool instead of opening a fresh one
from [database] url.
This is the recommended way to integrate atrg into an existing application that already manages its own connection pool — for example, a service that uses PostgreSQL for its business data and wants atrg’s internal tables (sessions, OAuth state) to live in the same database:
let pool = sqlx::PgPool::connect(&db_url).await?;
AtrgApp::new()
.with_db_pool(pool.into()) // accepts SqlitePool, PgPool, or DbPool
.mount(routes::api())
.run()
.awaitWhen a pool is provided this way, [database] url from atrg.toml
is ignored. atrg’s internal migrations are still applied to the
supplied pool on startup.
Sourcepub fn with_extension<T: Send + Sync + 'static>(self, value: T) -> Self
pub fn with_extension<T: Send + Sync + 'static>(self, value: T) -> Self
Register an app-specific extension value.
Extensions are type-erased values accessible from any handler via
AppState::extension::<T>() or
AppState::try_extension::<T>().
Each type can appear at most once — inserting a second value of the same type replaces the first.
§Examples
struct S3Client { bucket: String }
struct SmtpConfig { host: String }
AtrgApp::new()
.with_extension(S3Client { bucket: "my-blobs".into() })
.with_extension(SmtpConfig { host: "smtp.example.com".into() })
.mount(routes())
.run()
.awaitSourcepub fn on_event<F, Fut>(self, handler: F) -> Self
pub fn on_event<F, Fut>(self, handler: F) -> Self
Register a Jetstream event handler.
The handler is called for every event received from the Jetstream
firehose. It is spawned as a background task inside AtrgApp::run
when [jetstream] is present in atrg.toml.
Sourcepub fn on_firehose_event<F, Fut>(self, handler: F) -> Self
pub fn on_firehose_event<F, Fut>(self, handler: F) -> Self
Register a firehose event handler.
The handler is called for every event received from the AT Protocol
relay firehose (com.atproto.sync.subscribeRepos). It is spawned as
a background task inside AtrgApp::run when [firehose] is present
in atrg.toml.
Sourcepub fn with_feed_generator(self, feed_router: Router<AppState>) -> Self
pub fn with_feed_generator(self, feed_router: Router<AppState>) -> Self
Sourcepub fn with_labeler(self, labeler_router: Router<AppState>) -> Self
pub fn with_labeler(self, labeler_router: Router<AppState>) -> Self
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Boot the server.
This is the only async entry point. It:
- Initialises tracing (respects
RUST_LOG). - Loads
atrg.toml(or$ATRG_CONFIG). - Connects to SQLite and runs migrations.
- Builds
AppState(including the identity resolver). - Assembles the Axum router with CORS, tracing, and a JSON 404 fallback.
- Spawns optional cleanup tasks.
- Binds a TCP listener and serves.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AtrgApp
impl !RefUnwindSafe for AtrgApp
impl Send for AtrgApp
impl !Sync for AtrgApp
impl Unpin for AtrgApp
impl UnsafeUnpin for AtrgApp
impl !UnwindSafe for AtrgApp
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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