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;
|
use tokio::time::timeout;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod world;
|
mod scheduler;
|
||||||
mod feed;
|
mod feed;
|
||||||
mod worker;
|
mod worker;
|
||||||
mod trends;
|
mod trends;
|
||||||
|
@ -18,9 +18,9 @@ async fn main() {
|
||||||
.expect("Call with config.yaml")
|
.expect("Call with config.yaml")
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut world = world::World::new();
|
let mut scheduler = scheduler::Scheduler::new();
|
||||||
for host in config.hosts.into_iter() {
|
for host in config.hosts.into_iter() {
|
||||||
world.introduce(host);
|
scheduler.introduce(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
|
@ -43,9 +43,9 @@ async fn main() {
|
||||||
let mut workers_active = 0usize;
|
let mut workers_active = 0usize;
|
||||||
let (message_tx, mut message_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (message_tx, mut message_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
loop {
|
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 {
|
let next_task = if workers_active < config.max_workers {
|
||||||
world.dequeue()
|
scheduler.dequeue()
|
||||||
} else {
|
} else {
|
||||||
Err(Duration::from_secs(5))
|
Err(Duration::from_secs(5))
|
||||||
};
|
};
|
||||||
|
@ -56,15 +56,15 @@ async fn main() {
|
||||||
match message {
|
match message {
|
||||||
Message::Fetched { host, next_interval, latest_timestamp } => {
|
Message::Fetched { host, next_interval, latest_timestamp } => {
|
||||||
workers_active -= 1;
|
workers_active -= 1;
|
||||||
world.enqueue(host, next_interval, latest_timestamp);
|
scheduler.enqueue(host, next_interval, latest_timestamp);
|
||||||
}
|
}
|
||||||
Message::Error { host } => {
|
Message::Error { host } => {
|
||||||
workers_active -= 1;
|
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 } => {
|
Message::IntroduceHosts { hosts } => {
|
||||||
for host in hosts.into_iter() {
|
for host in hosts.into_iter() {
|
||||||
world.introduce(host);
|
scheduler.introduce(host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,14 @@ pub struct Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scheduler
|
/// Scheduler
|
||||||
pub struct World {
|
pub struct Scheduler {
|
||||||
instances: HashMap<String, Instance>,
|
instances: HashMap<String, Instance>,
|
||||||
queue: BTreeMap<Instant, String>,
|
queue: BTreeMap<Instant, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl World {
|
impl Scheduler {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
World {
|
Scheduler {
|
||||||
instances: HashMap::new(),
|
instances: HashMap::new(),
|
||||||
queue: BTreeMap::new(),
|
queue: BTreeMap::new(),
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user