2024-01-08 23:00:15 +00:00
|
|
|
use crate::{error::Error, future::BoxFuture, jobs::JobState};
|
|
|
|
use background_jobs::{Backoff, Job};
|
2022-12-21 22:51:17 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
|
|
pub(crate) struct RecordLastOnline;
|
|
|
|
|
|
|
|
impl RecordLastOnline {
|
|
|
|
#[tracing::instrument(skip(state))]
|
|
|
|
async fn perform(self, state: JobState) -> Result<(), Error> {
|
|
|
|
let nodes = state.state.last_online.take();
|
|
|
|
|
|
|
|
state.state.db.mark_last_seen(nodes).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 23:00:15 +00:00
|
|
|
impl Job for RecordLastOnline {
|
2022-12-21 22:51:17 +00:00
|
|
|
type State = JobState;
|
2024-01-08 23:00:15 +00:00
|
|
|
type Future = BoxFuture<'static, anyhow::Result<()>>;
|
2022-12-21 22:51:17 +00:00
|
|
|
|
|
|
|
const NAME: &'static str = "relay::jobs::RecordLastOnline";
|
|
|
|
const QUEUE: &'static str = "maintenance";
|
|
|
|
const BACKOFF: Backoff = Backoff::Linear(1);
|
|
|
|
|
|
|
|
fn run(self, state: Self::State) -> Self::Future {
|
|
|
|
Box::pin(async move { self.perform(state).await.map_err(Into::into) })
|
|
|
|
}
|
|
|
|
}
|