s/World/Scheduler?
This commit is contained in:
parent
c0ed026d89
commit
ef95c834e4
16
src/main.rs
16
src/main.rs
|
@ -2,7 +2,7 @@ use std::time::Duration;
|
|||
use tokio::time::timeout;
|
||||
|
||||
mod config;
|
||||
mod world;
|
||||
mod scheduler;
|
||||
mod feed;
|
||||
mod worker;
|
||||
mod trends;
|
||||
|
@ -18,9 +18,9 @@ async fn main() {
|
|||
.expect("Call with config.yaml")
|
||||
);
|
||||
|
||||
let mut world = world::World::new();
|
||||
let mut scheduler = scheduler::Scheduler::new();
|
||||
for host in config.hosts.into_iter() {
|
||||
world.introduce(host);
|
||||
scheduler.introduce(host);
|
||||
}
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
|
@ -43,9 +43,9 @@ async fn main() {
|
|||
let mut workers_active = 0usize;
|
||||
let (message_tx, mut message_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
loop {
|
||||
println!("{} workers active, queued {} of {}", workers_active, world.queue_len(), world.size());
|
||||
println!("{} workers active, queued {} of {}", workers_active, scheduler.queue_len(), scheduler.size());
|
||||
let next_task = if workers_active < config.max_workers {
|
||||
world.dequeue()
|
||||
scheduler.dequeue()
|
||||
} else {
|
||||
Err(Duration::from_secs(5))
|
||||
};
|
||||
|
@ -56,15 +56,15 @@ async fn main() {
|
|||
match message {
|
||||
Message::Fetched { host, next_interval, latest_timestamp } => {
|
||||
workers_active -= 1;
|
||||
world.enqueue(host, next_interval, latest_timestamp);
|
||||
scheduler.enqueue(host, next_interval, latest_timestamp);
|
||||
}
|
||||
Message::Error { host } => {
|
||||
workers_active -= 1;
|
||||
world.enqueue(host, Duration::from_secs(config.interval_after_error), None);
|
||||
scheduler.enqueue(host, Duration::from_secs(config.interval_after_error), None);
|
||||
}
|
||||
Message::IntroduceHosts { hosts } => {
|
||||
for host in hosts.into_iter() {
|
||||
world.introduce(host);
|
||||
scheduler.introduce(host);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ pub struct Instance {
|
|||
}
|
||||
|
||||
/// Scheduler
|
||||
pub struct World {
|
||||
pub struct Scheduler {
|
||||
instances: HashMap<String, Instance>,
|
||||
queue: BTreeMap<Instant, String>,
|
||||
}
|
||||
|
||||
impl World {
|
||||
impl Scheduler {
|
||||
pub fn new() -> Self {
|
||||
World {
|
||||
Scheduler {
|
||||
instances: HashMap::new(),
|
||||
queue: BTreeMap::new(),
|
||||
}
|
Loading…
Reference in New Issue