-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add taskman app, apply usage to each app
- Loading branch information
Showing
63 changed files
with
1,691 additions
and
1,508 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,20 @@ | ||
use std::time::Duration; | ||
|
||
use crate::{Error, Result}; | ||
|
||
const DURATION: Duration = Duration::from_secs(300); | ||
|
||
pub async fn start( | ||
app_name: &str, | ||
pool: sqlx::Pool<sqlx::Postgres>, | ||
shutdown: triggered::Listener, | ||
) -> Result<futures::future::BoxFuture<'static, Result>> { | ||
pub async fn start(app_name: &str, pool: sqlx::Pool<sqlx::Postgres>) { | ||
let pool_size_name = format!("{app_name}_db_pool_size"); | ||
let pool_idle_name = format!("{app_name}_db_pool_idle"); | ||
let join_handle = | ||
tokio::spawn(async move { run(pool_size_name, pool_idle_name, pool, shutdown).await }); | ||
|
||
Ok(Box::pin(async move { | ||
match join_handle.await { | ||
Ok(()) => Ok(()), | ||
Err(err) => Err(Error::from(err)), | ||
} | ||
})) | ||
tokio::spawn(async move { run(pool_size_name, pool_idle_name, pool).await }); | ||
} | ||
|
||
async fn run( | ||
size_name: String, | ||
idle_name: String, | ||
pool: sqlx::Pool<sqlx::Postgres>, | ||
shutdown: triggered::Listener, | ||
) { | ||
async fn run(size_name: String, idle_name: String, pool: sqlx::Pool<sqlx::Postgres>) { | ||
let mut trigger = tokio::time::interval(DURATION); | ||
|
||
loop { | ||
let shutdown = shutdown.clone(); | ||
trigger.tick().await; | ||
|
||
tokio::select! { | ||
_ = shutdown => { | ||
tracing::info!("db_store: MetricTracker shutting down"); | ||
break; | ||
} | ||
_ = trigger.tick() => { | ||
metrics::gauge!(size_name.clone(), pool.size() as f64); | ||
metrics::gauge!(idle_name.clone(), pool.num_idle() as f64); | ||
} | ||
} | ||
metrics::gauge!(size_name.clone(), pool.size() as f64); | ||
metrics::gauge!(idle_name.clone(), pool.num_idle() as f64); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.