mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-06 01:22:16 +00:00
handlers: replace unbounded per-URL spawn with a bounded job channel
The 8-permit semaphore was acquired inside the spawned task, so a burst queued unlimited tasks (each cloning Bot+Message) and nothing tracked them at shutdown — in-flight sends fired after the stop notice. URL work now flows through a 256-slot mpsc drained by 8 workers started from main; a full channel backpressures the per-chat handler, and shutdown sets URL_STOP so workers stop pulling.
This commit is contained in:
@@ -62,6 +62,10 @@ async fn main() {
|
||||
.await;
|
||||
log::info!("task queue worker started");
|
||||
|
||||
// URL job workers: bounded channel + fixed pool for per-URL work.
|
||||
handlers::start_url_workers().await;
|
||||
log::info!("url workers started");
|
||||
|
||||
// Pixiv login validation (user request): a failed login notifies the
|
||||
// admin and disables pixiv for this process.
|
||||
if site::pixiv::enabled() {
|
||||
@@ -174,6 +178,7 @@ async fn main() {
|
||||
// Graceful stop (Ctrl+C / SIGTERM): stop the sweep, notify the admin, drain the queue.
|
||||
log::info!("Stopping bot");
|
||||
let _ = stop_tx.send(true);
|
||||
handlers::stop_url_workers();
|
||||
if let Some(admin) = CONFIG.admin_ids.first() {
|
||||
let _ = bot.send_message(ChatId(*admin), "Shutting down...").await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user