mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-03 00:52:10 +00:00
fix: stop persistent queue before URL workers
This commit is contained in:
@@ -263,18 +263,19 @@ async fn main() {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Graceful stop (Ctrl+C / SIGTERM): stop the sweep, notify the admin,
|
// Graceful stop (Ctrl+C / SIGTERM): stop the queue first so no new
|
||||||
// drain the queue. Bounded: a worker mid-download (30 s timeout) or a
|
// persistent task is leased while the URL workers drain. The two drains
|
||||||
// long ugoira encode must not hold the shutdown hostage forever.
|
// share the bounded shutdown budget; URL work may legitimately outlive it,
|
||||||
|
// but the queue must not be left running until process exit.
|
||||||
log::info!("Stopping bot");
|
log::info!("Stopping bot");
|
||||||
const SHUTDOWN_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
|
const SHUTDOWN_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
|
||||||
let shutdown = async {
|
let shutdown = async {
|
||||||
let _ = stop_tx.send(true);
|
let _ = stop_tx.send(true);
|
||||||
|
TASK_QUEUE.stop().await;
|
||||||
handlers::stop_url_workers().await;
|
handlers::stop_url_workers().await;
|
||||||
if let Some(admin) = CONFIG.admin_ids.first() {
|
if let Some(admin) = CONFIG.admin_ids.first() {
|
||||||
let _ = bot.send_message(ChatId(*admin), "Shutting down...").await;
|
let _ = bot.send_message(ChatId(*admin), "Shutting down...").await;
|
||||||
}
|
}
|
||||||
TASK_QUEUE.stop().await;
|
|
||||||
};
|
};
|
||||||
if tokio::time::timeout(SHUTDOWN_TIMEOUT, shutdown)
|
if tokio::time::timeout(SHUTDOWN_TIMEOUT, shutdown)
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user