mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 14:52:31 +00:00
only production, better sigterm handling
This commit is contained in:
1 parent
e79e3186ba
commit
ed3c4c6d59
5 files changed
+23
-7
No files matched your search
+1
@@ -60,6 +60,7 @@ SELECT
|
||||
CAST(COALESCE(SUM(maybe_credits_granted), 0) AS UNSIGNED) AS `credits_granted!: u64`
|
||||
FROM user_spend_events
|
||||
WHERE maybe_user_token IS NOT NULL
|
||||
AND is_production = TRUE
|
||||
AND payment_occurred_at >= ?
|
||||
AND payment_occurred_at < ?
|
||||
GROUP BY maybe_user_token, payments_namespace
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ where
|
||||
SELECT DISTINCT payments_namespace AS `payments_namespace!: PaymentsNamespace`
|
||||
FROM user_spend_events
|
||||
WHERE maybe_user_token IS NOT NULL
|
||||
AND is_production = TRUE
|
||||
"#,
|
||||
)
|
||||
.fetch_all(args.mysql_executor)
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ SELECT
|
||||
FROM user_spend_events
|
||||
WHERE maybe_user_token = ?
|
||||
AND payments_namespace = ?
|
||||
AND is_production = TRUE
|
||||
ORDER BY payment_occurred_at ASC
|
||||
"#,
|
||||
args.user_token.as_str(),
|
||||
|
||||
+1
@@ -29,6 +29,7 @@ where
|
||||
SELECT DISTINCT maybe_user_token AS `user_token!: UserToken`
|
||||
FROM user_spend_events
|
||||
WHERE maybe_user_token IS NOT NULL
|
||||
AND is_production = TRUE
|
||||
AND payments_namespace = ?
|
||||
AND maybe_user_token > ?
|
||||
ORDER BY maybe_user_token
|
||||
|
||||
@@ -24,6 +24,7 @@ use jobs_common::job_stats::JobStats;
|
||||
use server_environment::ServerEnvironment;
|
||||
use shared_env_var_config::logging::DEFAULT_RUST_LOG;
|
||||
use shared_env_var_config::mysql::env_get_mysql_connection_string_or_default;
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
|
||||
use crate::http_server::run_http_server::{launch_http_server, CreateServerArgs};
|
||||
use crate::job::main_loop::main_loop;
|
||||
@@ -147,18 +148,29 @@ async fn main() -> AnyhowResult<()> {
|
||||
warn!("HTTP server thread is shut down.");
|
||||
});
|
||||
|
||||
// Listen for SIGTERM / Ctrl-C to trigger graceful shutdown.
|
||||
// Listen for SIGTERM (k8s pod termination) and SIGINT (Ctrl-C) to trigger
|
||||
// graceful shutdown of the main loop.
|
||||
let application_shutdown_for_signal = application_shutdown.clone();
|
||||
tokio::spawn(async move {
|
||||
match tokio::signal::ctrl_c().await {
|
||||
Ok(()) => {
|
||||
info!("Received shutdown signal. Shutting down...");
|
||||
application_shutdown_for_signal.set(true);
|
||||
}
|
||||
let mut sigterm = match signal(SignalKind::terminate()) {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
warn!("Error listening for shutdown signal: {:?}", err);
|
||||
warn!("Failed to install SIGTERM handler: {:?}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let mut sigint = match signal(SignalKind::interrupt()) {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
warn!("Failed to install SIGINT handler: {:?}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
tokio::select! {
|
||||
_ = sigterm.recv() => info!("Received SIGTERM. Shutting down..."),
|
||||
_ = sigint.recv() => info!("Received SIGINT. Shutting down..."),
|
||||
}
|
||||
application_shutdown_for_signal.set(true);
|
||||
});
|
||||
|
||||
main_loop(job_dependencies).await;
|
||||
|
||||
Reference in new issue
Block a user