relay/src/jobs/process_listeners.rs

37 lines
1 KiB
Rust
Raw Normal View History

2021-09-18 17:55:39 +00:00
use crate::{
error::Error,
future::BoxFuture,
2021-09-18 17:55:39 +00:00
jobs::{instance::QueryInstance, nodeinfo::QueryNodeinfo, JobState},
};
use background_jobs::Job;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2021-02-10 04:17:20 +00:00
pub(crate) struct Listeners;
impl Listeners {
2022-11-01 20:57:33 +00:00
#[tracing::instrument(name = "Spawn query instances", skip(state))]
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? {
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?;
}
Ok(())
}
}
impl Job for Listeners {
type State = JobState;
type Future = BoxFuture<'static, anyhow::Result<()>>;
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
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) })
}
}