Compare commits
3 Commits
25a9005375
...
e1440c6d57
| Author | SHA1 | Date | |
|---|---|---|---|
|
e1440c6d57
|
|||
|
e4d9af1e1c
|
|||
|
f28d9f5d14
|
26
.github/workflows/ci.yml
vendored
Normal file
26
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
env:
|
||||||
|
RUST_VERSION: "1.90"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ env.RUST_VERSION }}
|
||||||
|
|
||||||
|
- name: cargo check
|
||||||
|
run: cargo check --examples
|
||||||
|
|
||||||
|
- name: cargo build
|
||||||
|
run: cargo build --examples
|
||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -49,7 +49,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum-app-wrapper"
|
name = "axum-app-wrapper"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
});
|
});
|
||||||
let metrics_registry = Arc::new(Metrics::new());
|
let metrics_registry = Arc::new(Metrics::new());
|
||||||
|
|
||||||
|
// Create your plugins using AdHocPlugin
|
||||||
let config_plugin = AdHocPlugin::<AppState>::new()
|
let config_plugin = AdHocPlugin::<AppState>::new()
|
||||||
.on_init(async move |mut state| {
|
.on_init(async |mut state| {
|
||||||
state.insert(config);
|
state.insert(config);
|
||||||
Ok(state)
|
Ok(state)
|
||||||
})
|
})
|
||||||
@@ -53,7 +54,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let metrics_plugin = AdHocPlugin::<AppState>::new()
|
let metrics_plugin = AdHocPlugin::<AppState>::new()
|
||||||
.on_init(async move |mut state| {
|
.on_init(async |mut state| {
|
||||||
state.insert(metrics_registry);
|
state.insert(metrics_registry);
|
||||||
Ok(state)
|
Ok(state)
|
||||||
})
|
})
|
||||||
@@ -69,6 +70,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Register your plugins in the desired order
|
||||||
let app = App::<AppState>::new()
|
let app = App::<AppState>::new()
|
||||||
.register(config_plugin)
|
.register(config_plugin)
|
||||||
.register(metrics_plugin);
|
.register(metrics_plugin);
|
||||||
@@ -79,12 +81,13 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let addr: SocketAddr = "127.0.0.1:3000".parse()?;
|
let addr: SocketAddr = "127.0.0.1:3000".parse()?;
|
||||||
let listener = tokio::net::TcpListener::bind(addr).await?;
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||||
|
|
||||||
|
// Start the axum server with graceful shutdown
|
||||||
axum::serve(listener, router)
|
axum::serve(listener, router)
|
||||||
.with_graceful_shutdown(async {
|
.with_graceful_shutdown(async {
|
||||||
tokio::signal::ctrl_c()
|
tokio::signal::ctrl_c()
|
||||||
.await
|
.await
|
||||||
.expect("failed to listen for ctrl-c");
|
.expect("failed to listen for ctrl-c");
|
||||||
on_shutdown.await;
|
on_shutdown.await; // Run the on_shutdown future for graceful shutdown
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user