fix: make archive shutdown responsive
This commit is contained in:
parent
3c445411e9
commit
b5b83b955a
3 changed files with 20 additions and 27 deletions
|
@ -147,6 +147,7 @@ async fn download(
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::api::v1::bench::Submission;
|
use crate::api::v1::bench::Submission;
|
||||||
use crate::api::v1::bench::SubmissionType;
|
use crate::api::v1::bench::SubmissionType;
|
||||||
|
use crate::api::v1::get_random;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::mcaptcha::PerformanceAnalytics;
|
use crate::mcaptcha::PerformanceAnalytics;
|
||||||
use crate::mcaptcha::Secret;
|
use crate::mcaptcha::Secret;
|
||||||
|
@ -181,6 +182,7 @@ mod tests {
|
||||||
|
|
||||||
let payload = super::MCaptchaInstance {
|
let payload = super::MCaptchaInstance {
|
||||||
url: mcaptcha_instance.clone(),
|
url: mcaptcha_instance.clone(),
|
||||||
|
auth_token: get_random(23),
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = test::call_service(
|
let resp = test::call_service(
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::types::time::OffsetDateTime;
|
use sqlx::types::time::OffsetDateTime;
|
||||||
use sqlx::types::Uuid;
|
use sqlx::types::Uuid;
|
||||||
|
@ -218,27 +217,27 @@ impl Archiver {
|
||||||
) -> ServiceResult<(Sender<bool>, JoinHandle<()>)> {
|
) -> ServiceResult<(Sender<bool>, JoinHandle<()>)> {
|
||||||
let (tx, mut rx) = oneshot::channel();
|
let (tx, mut rx) = oneshot::channel();
|
||||||
|
|
||||||
|
fn can_run(rx: &mut oneshot::Receiver<bool>) -> bool {
|
||||||
|
match rx.try_recv() {
|
||||||
|
Err(TryRecvError::Empty) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let job = async move {
|
let job = async move {
|
||||||
loop {
|
loop {
|
||||||
// let rx = self.rx.as_mut().unwrap();
|
if !can_run(&mut rx) {
|
||||||
match rx.try_recv() {
|
log::info!("Killing archive loop: received signal");
|
||||||
// The channel is currently empty
|
break;
|
||||||
Ok(_) => {
|
}
|
||||||
|
|
||||||
|
for _ in 0..data.settings.publish.duration {
|
||||||
|
if !can_run(&mut rx) {
|
||||||
log::info!("Killing archive loop: received signal");
|
log::info!("Killing archive loop: received signal");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(TryRecvError::Empty) => {
|
tokio::time::sleep(std::time::Duration::new(1, 0)).await;
|
||||||
let _ = self.archive(&data).await;
|
|
||||||
|
|
||||||
tokio::time::sleep(std::time::Duration::new(
|
|
||||||
data.settings.publish.duration,
|
|
||||||
0,
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
Err(TryRecvError::Closed) => break,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = self.archive(&data).await;
|
let _ = self.archive(&data).await;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -111,17 +111,9 @@ impl MCaptchaClient for MCaptchaClientReqwest {
|
||||||
auth_token: String,
|
auth_token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = S {
|
let msg = S { secret, auth_token };
|
||||||
secret,
|
|
||||||
auth_token,
|
|
||||||
};
|
|
||||||
mcaptcha.set_path("/api/v1/survey/secret");
|
mcaptcha.set_path("/api/v1/survey/secret");
|
||||||
self.client
|
self.client.post(mcaptcha).json(&msg).send().await.unwrap();
|
||||||
.post(mcaptcha)
|
|
||||||
.json(&msg)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn download_benchmarks(
|
async fn download_benchmarks(
|
||||||
|
@ -192,7 +184,7 @@ pub mod tests {
|
||||||
) -> ServiceResult<()> {
|
) -> ServiceResult<()> {
|
||||||
mcaptcha.set_path("/api/v1/survey/secret");
|
mcaptcha.set_path("/api/v1/survey/secret");
|
||||||
let mut x = self.client.write().unwrap();
|
let mut x = self.client.write().unwrap();
|
||||||
x.insert(mcaptcha.to_string(), secret.secret.to_owned());
|
x.insert(mcaptcha.to_string(), secret);
|
||||||
drop(x);
|
drop(x);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue