This commit is contained in:
2023-08-26 00:17:48 +02:00
parent 937e9c16d4
commit 6610521103
2 changed files with 14 additions and 14 deletions

View File

@@ -11,7 +11,7 @@ use teloxide::{
prelude::*,
types::*,
};
use tokio::time::sleep;
use tokio::time::{self};
use tokio_util::compat::FuturesAsyncReadCompatExt;
use tracing::log;
@@ -507,7 +507,11 @@ async fn wait_archive(
task_id: String,
message: Message,
) -> BotHandlerInternal {
let mut interval = time::interval(Duration::from_secs(5));
let task = loop {
interval.tick().await;
let task = match get_task(task_id.clone()).await {
Ok(v) => v,
Err(err) => {
@@ -535,8 +539,6 @@ async fn wait_archive(
.reply_markup(get_check_keyboard(task.id))
.send()
.await?;
sleep(Duration::from_secs(5)).await;
};
if task.status != TaskStatus::Complete {

View File

@@ -24,7 +24,7 @@ use tokio::sync::RwLock;
use smallvec::SmallVec;
use teloxide::adaptors::throttle::Limits;
use teloxide::types::{BotCommand, UpdateKind};
use tokio::time::{sleep, Duration};
use tokio::time::{sleep, Duration, self};
use tower_http::trace::TraceLayer;
use teloxide::prelude::*;
@@ -300,21 +300,19 @@ impl BotsManager {
manager.start_axum_server().await;
let mut i = 0;
let mut interval = time::interval(Duration::from_secs(5));
loop {
for _i in 0..30 {
interval.tick().await;
if !running.load(Ordering::SeqCst) {
manager.stop_all().await;
return;
};
if i == 0 {
manager.check().await;
}
sleep(Duration::from_secs(1)).await;
i = (i + 1) % 30;
manager.check().await;
}
}
}