Add service module

To multiplex discord bot and http server in shuttle
This commit is contained in:
Aadi Desai 2023-09-23 23:14:26 +01:00
parent d62fabb048
commit 1b8914cf67
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM

20
src/service.rs Normal file
View file

@ -0,0 +1,20 @@
use crate::{Data, Error};
pub(crate) struct NanoBot {
pub discord: poise::FrameworkBuilder<Data, Error>,
pub router: axum::Router,
}
#[shuttle_runtime::async_trait]
impl shuttle_runtime::Service for NanoBot {
async fn bind(mut self, addr: std::net::SocketAddr) -> Result<(), shuttle_runtime::Error> {
let serve = axum::Server::bind(&addr).serve(self.router.into_make_service());
tokio::select! {
_ = self.discord.run_autosharded() => {},
_ = serve => {},
};
Ok(())
}
}