2020-03-23 03:52:42 +00:00
|
|
|
use crate::jobs::{instance::QueryInstance, nodeinfo::QueryNodeinfo, JobState};
|
|
|
|
use anyhow::Error;
|
2020-03-30 15:45:44 +00:00
|
|
|
use background_jobs::{ActixJob, Processor};
|
2020-03-23 03:52:42 +00:00
|
|
|
use std::{future::Future, pin::Pin};
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
|
|
pub struct Listeners;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct ListenersProcessor;
|
|
|
|
|
|
|
|
impl Listeners {
|
|
|
|
async fn perform(self, state: JobState) -> Result<(), Error> {
|
|
|
|
for listener in state.state.listeners().await {
|
|
|
|
state
|
|
|
|
.job_server
|
2020-03-25 22:10:10 +00:00
|
|
|
.queue(QueryInstance::new(listener.clone()))?;
|
|
|
|
state.job_server.queue(QueryNodeinfo::new(listener))?;
|
2020-03-23 03:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 15:45:44 +00:00
|
|
|
impl ActixJob for Listeners {
|
2020-03-23 03:52:42 +00:00
|
|
|
type State = JobState;
|
|
|
|
type Processor = ListenersProcessor;
|
2020-03-30 15:45:44 +00:00
|
|
|
type Future = Pin<Box<dyn Future<Output = Result<(), Error>>>>;
|
2020-03-23 03:52:42 +00:00
|
|
|
|
|
|
|
fn run(self, state: Self::State) -> Self::Future {
|
2020-03-30 15:45:44 +00:00
|
|
|
Box::pin(self.perform(state))
|
2020-03-23 03:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Processor for ListenersProcessor {
|
|
|
|
type Job = Listeners;
|
|
|
|
|
|
|
|
const NAME: &'static str = "ProcessListenersProcessor";
|
|
|
|
const QUEUE: &'static str = "default";
|
|
|
|
}
|