mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-15 23:08:55 +00:00
Tune announcer performance
This commit is contained in:
parent
063c8baaa9
commit
5d6e537ac2
7 changed files with 15 additions and 3 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1720,6 +1720,7 @@ dependencies = [
|
||||||
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"codeforces 0.1.0 (git+https://github.com/natsukagami/rust-codeforces-api)",
|
"codeforces 0.1.0 (git+https://github.com/natsukagami/rust-codeforces-api)",
|
||||||
|
"crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1776,6 +1777,7 @@ dependencies = [
|
||||||
name = "youmubot-prelude"
|
name = "youmubot-prelude"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -15,6 +15,7 @@ regex = "1"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
rayon = "1"
|
rayon = "1"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
crossbeam-channel = "0.4"
|
||||||
|
|
||||||
youmubot-prelude = { path = "../youmubot-prelude" }
|
youmubot-prelude = { path = "../youmubot-prelude" }
|
||||||
youmubot-db = { path = "../youmubot-db" }
|
youmubot-db = { path = "../youmubot-db" }
|
||||||
|
|
|
@ -39,6 +39,8 @@ fn update_user(
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
cfu: &mut CfUser,
|
cfu: &mut CfUser,
|
||||||
) -> CommandResult {
|
) -> CommandResult {
|
||||||
|
// Ensure this takes 200ms
|
||||||
|
let after = crossbeam_channel::after(std::time::Duration::from_secs_f32(0.2));
|
||||||
let info = User::info(reqwest, &[cfu.handle.as_str()])?
|
let info = User::info(reqwest, &[cfu.handle.as_str()])?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
|
@ -91,6 +93,7 @@ fn update_user(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
after.recv().ok();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ impl Client {
|
||||||
|
|
||||||
fn build_request(&self, r: RequestBuilder) -> Result<Response, Error> {
|
fn build_request(&self, r: RequestBuilder) -> Result<Response, Error> {
|
||||||
let v = r.query(&[("k", &*self.key)]).build()?;
|
let v = r.query(&[("k", &*self.key)]).build()?;
|
||||||
dbg!(v.url());
|
// dbg!(v.url());
|
||||||
Ok(self.client.execute(v)?)
|
Ok(self.client.execute(v)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,3 +12,4 @@ youmubot-db = { path = "../youmubot-db" }
|
||||||
crossbeam-channel = "0.4"
|
crossbeam-channel = "0.4"
|
||||||
reqwest = "0.10"
|
reqwest = "0.10"
|
||||||
rayon = "1"
|
rayon = "1"
|
||||||
|
chrono = "0.4"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{AppData, GetCloned};
|
use crate::{AppData, GetCloned};
|
||||||
|
use crossbeam_channel::after;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::{
|
framework::standard::{
|
||||||
|
@ -153,12 +154,16 @@ impl AnnouncerHandler {
|
||||||
let keys = self.announcers.keys().cloned().collect::<Vec<_>>();
|
let keys = self.announcers.keys().cloned().collect::<Vec<_>>();
|
||||||
self.data.write().insert::<Self>(keys.clone());
|
self.data.write().insert::<Self>(keys.clone());
|
||||||
spawn(move || loop {
|
spawn(move || loop {
|
||||||
|
eprintln!("{}: announcer started scanning", chrono::Utc::now());
|
||||||
|
let after_timer = after(cooldown);
|
||||||
for key in &keys {
|
for key in &keys {
|
||||||
|
eprintln!(" - scanning key `{}`", key);
|
||||||
if let Err(e) = self.announce(key) {
|
if let Err(e) = self.announce(key) {
|
||||||
dbg!(e);
|
dbg!(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::thread::sleep(cooldown);
|
eprintln!("{}: announcer finished scanning", chrono::Utc::now());
|
||||||
|
after_timer.recv().ok();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ fn main() {
|
||||||
println!("codeforces enabled.");
|
println!("codeforces enabled.");
|
||||||
|
|
||||||
client.with_framework(fw);
|
client.with_framework(fw);
|
||||||
announcers.scan(std::time::Duration::from_secs(300));
|
announcers.scan(std::time::Duration::from_secs(120));
|
||||||
|
|
||||||
println!("Starting...");
|
println!("Starting...");
|
||||||
if let Err(v) = client.start() {
|
if let Err(v) = client.start() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue