prepare first release with graceful shutdown + containerfile + push to
hub script
This commit is contained in:
+13
-2
@@ -5,6 +5,7 @@ use crate::{
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::{error, info, instrument};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
@@ -54,13 +55,23 @@ impl Bot {
|
||||
pub async fn start(
|
||||
&self,
|
||||
mut rx: tokio::sync::mpsc::Receiver<WebhookType>,
|
||||
shutdown: CancellationToken,
|
||||
) -> anyhow::Result<()> {
|
||||
info!("Bot started");
|
||||
|
||||
let sem = Arc::new(tokio::sync::Semaphore::new(self.max_concurrent));
|
||||
let mut tasks = tokio::task::JoinSet::new();
|
||||
|
||||
while let Some(wb) = rx.recv().await {
|
||||
loop {
|
||||
let wb = tokio::select! {
|
||||
biased;
|
||||
_ = shutdown.cancelled() => break,
|
||||
msg = rx.recv() => match msg {
|
||||
Some(wb) => wb,
|
||||
None => break,
|
||||
},
|
||||
};
|
||||
|
||||
// Drain completed tasks to avoid the JoinSet growing unbounded
|
||||
while let Some(res) = tasks.try_join_next() {
|
||||
if let Err(e) = res {
|
||||
@@ -82,7 +93,7 @@ impl Bot {
|
||||
// properly before returning
|
||||
tasks.join_all().await;
|
||||
|
||||
info!("Bot shutting down, channel closed");
|
||||
info!("Bot shutting down complete");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user