mirror of
https://codeberg.org/YGGverse/ytd.git
synced 2026-04-08 04:55:26 +00:00
implement sleep option to prevent server abuse
This commit is contained in:
parent
2ea58cc9c3
commit
e462665342
3 changed files with 17 additions and 5 deletions
|
|
@ -1,6 +1,10 @@
|
|||
# Persist processed entries between sessions
|
||||
database = "database.redb"
|
||||
|
||||
# Iterator delay in seconds (prevents server abuse)
|
||||
# * unset or comment to run asap
|
||||
sleep = 1
|
||||
|
||||
# Update channels queue, in seconds (activates daemon mode)
|
||||
# * unset or comment to run once
|
||||
# update = 60
|
||||
|
|
|
|||
|
|
@ -12,4 +12,7 @@ pub struct Config {
|
|||
/// Repeat delay in seconds (activates daemon mode)
|
||||
/// * None to run once
|
||||
pub update: Option<u64>,
|
||||
/// Iterator delay in seconds (prevents server abuse)
|
||||
/// * None to run asap
|
||||
pub sleep: Option<u64>,
|
||||
}
|
||||
|
|
|
|||
15
src/main.rs
15
src/main.rs
|
|
@ -9,7 +9,7 @@ use config::Config;
|
|||
use database::Database;
|
||||
use log::*;
|
||||
use rustypipe::client::RustyPipe;
|
||||
use std::{env::var, process::Command, time::Duration};
|
||||
use std::{env::var, process::Command, thread, time::Duration};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
|
@ -31,6 +31,7 @@ async fn main() {
|
|||
let config: Config =
|
||||
toml::from_str(&std::fs::read_to_string(&argument.config).unwrap()).unwrap();
|
||||
let update = config.update.map(Duration::from_secs);
|
||||
let sleep = config.sleep.map(Duration::from_secs);
|
||||
let mut database = Database::new(&config.database).unwrap();
|
||||
|
||||
let rp = RustyPipe::new();
|
||||
|
|
@ -79,7 +80,7 @@ async fn main() {
|
|||
}) {
|
||||
match database.process(&item.id) {
|
||||
Ok(()) => debug!(
|
||||
"command `{cmd}` for channel `{c}` successful: `{:?}`",
|
||||
"exec `{cmd}` for channel `{c}` successful: `{:?}`",
|
||||
response
|
||||
),
|
||||
Err(e) => error!(
|
||||
|
|
@ -89,13 +90,13 @@ async fn main() {
|
|||
}
|
||||
} else {
|
||||
warn!(
|
||||
"unexpected command `{cmd}` for channel `{c}`: `{:?}`",
|
||||
"unexpected exec `{cmd}` for channel `{c}`: `{:?}`",
|
||||
response
|
||||
)
|
||||
}
|
||||
} else {
|
||||
warn!(
|
||||
"command `{cmd}` for channel `{c}` failed: `{:?}`",
|
||||
"exec `{cmd}` for channel `{c}` failed: `{:?}`",
|
||||
response
|
||||
)
|
||||
}
|
||||
|
|
@ -105,6 +106,10 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if let Some(duration) = sleep {
|
||||
debug!("await {} seconds to continue...", duration.as_secs());
|
||||
thread::sleep(duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => warn!("can't scrape channel `{c}`: `{e}`"),
|
||||
|
|
@ -116,7 +121,7 @@ async fn main() {
|
|||
"queue completed; await {} seconds to continue...",
|
||||
duration.as_secs()
|
||||
);
|
||||
std::thread::sleep(duration)
|
||||
thread::sleep(duration)
|
||||
}
|
||||
None => {
|
||||
debug!("all tasks completed; exit.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue