-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: removing actix web server in favour of a plain loop
- Loading branch information
Showing
22 changed files
with
424 additions
and
1,795 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use anyhow::anyhow; | ||
use metrics_exporter_prometheus::PrometheusBuilder; | ||
|
||
pub const SUCCESSFULLY_REFRESHED_GAUGE: &str = "successfully_refreshed"; | ||
pub const FAILED_TO_REFRESH_GAUGE: &str = "failed_to_refresh"; | ||
pub const REFRESH_TOTAL: &str = "refresh_total"; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Metrics; | ||
|
||
impl Metrics { | ||
pub fn new() -> anyhow::Result<Self> { | ||
PrometheusBuilder::new().install().map_err(|e| { | ||
tracing::error!("Failed to install prometheus exporter: {}", e); | ||
anyhow!(e) | ||
})?; | ||
|
||
metrics::describe_gauge!( | ||
SUCCESSFULLY_REFRESHED_GAUGE, | ||
"The number of successfully refreshed connections" | ||
); | ||
|
||
metrics::describe_gauge!( | ||
FAILED_TO_REFRESH_GAUGE, | ||
"The number of failed to refresh connections" | ||
); | ||
|
||
metrics::describe_gauge!(REFRESH_TOTAL, "The total number of refreshes"); | ||
|
||
Ok(Self) | ||
} | ||
|
||
pub fn add_refreshed(&self, value: u64) { | ||
metrics::increment_gauge!(SUCCESSFULLY_REFRESHED_GAUGE, value as f64); | ||
metrics::increment_gauge!(REFRESH_TOTAL, value as f64); | ||
} | ||
|
||
pub fn add_failed_to_refresh(&self, value: u64) { | ||
metrics::increment_gauge!(FAILED_TO_REFRESH_GAUGE, value as f64); | ||
metrics::increment_gauge!(REFRESH_TOTAL, value 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
mod metrics; | ||
mod parameter; | ||
mod refresh; | ||
mod storage; | ||
mod token; | ||
|
||
pub use metrics::*; | ||
pub use parameter::*; | ||
pub use refresh::*; | ||
pub use storage::*; | ||
pub use token::*; |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
use dotenvy::dotenv; | ||
use envconfig::Envconfig; | ||
use integrationos_domain::telemetry::{get_subscriber, init_subscriber}; | ||
use oauth_api::{Application, Configuration}; | ||
use oauth_api::{refresh, AppState, Refresh, RefreshConfig}; | ||
use std::time::Duration; | ||
|
||
#[actix_web::main] | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
dotenv().ok(); | ||
|
||
let suscriber = get_subscriber("oauth-api".into(), "info".into(), std::io::stdout); | ||
init_subscriber(suscriber); | ||
|
||
let configuration = Configuration::init_from_env()?; | ||
let configuration = RefreshConfig::init_from_env()?; | ||
|
||
let address = configuration.server().app_url().to_string(); | ||
let application = Application::start(&configuration).await?; | ||
tracing::info!( | ||
"Starting application with configuration: {}{:#?}{}", | ||
"\n", | ||
&configuration, | ||
"\n" | ||
); | ||
let state = AppState::try_from(configuration.clone()).await?; | ||
|
||
tracing::info!("Starting server at {}", &address); | ||
application.spawn().await?; | ||
let sleep_timer = Duration::from_secs(configuration.sleep_timer()); | ||
let refresh_before = configuration.refresh_before(); | ||
|
||
Ok(()) | ||
loop { | ||
let res = refresh( | ||
Refresh::new(refresh_before), | ||
state.connections().clone(), | ||
state.secrets().clone(), | ||
state.oauths().clone(), | ||
state.client().clone(), | ||
state.metrics().clone(), | ||
) | ||
.await; | ||
if let Err(e) = res { | ||
tracing::warn!("Failed to send refresh message: {:?}", e); | ||
} | ||
|
||
tracing::info!("Sleeping for {} seconds", sleep_timer.as_secs()); | ||
tokio::time::sleep(sleep_timer).await; | ||
} | ||
} |
Oops, something went wrong.