background-jobs/jobs-actix/src/pinger.rs

25 lines
488 B
Rust
Raw Normal View History

2019-05-27 17:29:11 +00:00
use actix::{Actor, Addr, AsyncContext, Context};
2018-12-16 18:43:44 +00:00
use std::time::Duration;
2019-05-27 17:29:11 +00:00
use crate::{CheckDb, Server};
2018-12-16 18:43:44 +00:00
2019-05-27 17:29:11 +00:00
pub struct Pinger {
server: Addr<Server>,
2018-12-16 18:43:44 +00:00
}
2019-05-27 17:29:11 +00:00
impl Pinger {
pub fn new(server: Addr<Server>) -> Self {
2018-12-16 18:43:44 +00:00
Pinger { server }
}
}
2019-05-27 17:29:11 +00:00
impl Actor for Pinger {
2018-12-16 18:43:44 +00:00
type Context = Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
ctx.run_interval(Duration::from_secs(1), |actor, _| {
actor.server.do_send(CheckDb);
});
}
}