2021-09-18 17:55:39 +00:00
|
|
|
use crate::{
|
|
|
|
error::Error,
|
2024-01-08 23:00:15 +00:00
|
|
|
future::BoxFuture,
|
2021-09-18 17:55:39 +00:00
|
|
|
jobs::{instance::QueryInstance, nodeinfo::QueryNodeinfo, JobState},
|
|
|
|
};
|
2024-01-08 23:00:15 +00:00
|
|
|
use background_jobs::Job;
|
2020-03-23 03:52:42 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
2021-02-10 04:17:20 +00:00
|
|
|
pub(crate) struct Listeners;
|
2020-03-23 03:52:42 +00:00
|
|
|
|
|
|
|
impl Listeners {
|
2022-11-01 20:57:33 +00:00
|
|
|
#[tracing::instrument(name = "Spawn query instances", skip(state))]
|
2020-03-23 03:52:42 +00:00
|
|
|
async fn perform(self, state: JobState) -> Result<(), Error> {
|
2021-02-10 04:05:06 +00:00
|
|
|
for actor_id in state.state.db.connected_ids().await? {
|
2020-03-23 03:52:42 +00:00
|
|
|
state
|
|
|
|
.job_server
|
2022-11-01 20:57:33 +00:00
|
|
|
.queue(QueryInstance::new(actor_id.clone()))
|
|
|
|
.await?;
|
2021-10-11 19:19:32 +00:00
|
|
|
state.job_server.queue(QueryNodeinfo::new(actor_id)).await?;
|
2020-03-23 03:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 23:00:15 +00:00
|
|
|
impl Job for Listeners {
|
2020-03-23 03:52:42 +00:00
|
|
|
type State = JobState;
|
2024-01-08 23:00:15 +00:00
|
|
|
type Future = BoxFuture<'static, anyhow::Result<()>>;
|
2020-03-23 03:52:42 +00:00
|
|
|
|
2020-04-21 01:03:46 +00:00
|
|
|
const NAME: &'static str = "relay::jobs::Listeners";
|
2022-11-20 03:32:45 +00:00
|
|
|
const QUEUE: &'static str = "maintenance";
|
2020-04-21 00:56:50 +00:00
|
|
|
|
2020-03-23 03:52:42 +00:00
|
|
|
fn run(self, state: Self::State) -> Self::Future {
|
2021-09-18 17:55:39 +00:00
|
|
|
Box::pin(async move { self.perform(state).await.map_err(Into::into) })
|
2020-03-23 03:52:42 +00:00
|
|
|
}
|
|
|
|
}
|