2019-02-22 07:15:48 +01:00
|
|
|
use actix::prelude::*;
|
2019-02-24 05:15:37 +01:00
|
|
|
use std::time::Duration;
|
2019-02-22 07:15:48 +01:00
|
|
|
|
|
|
|
use constants::PURGE_TIMEOUT;
|
2019-02-24 05:15:37 +01:00
|
|
|
use event::PurgeEvent;
|
|
|
|
use server::QueryServer;
|
2019-02-22 07:15:48 +01:00
|
|
|
|
|
|
|
pub struct IntervalActor {
|
|
|
|
// Store any addresses we require
|
|
|
|
server: actix::Addr<QueryServer>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntervalActor {
|
|
|
|
pub fn new(server: actix::Addr<QueryServer>) -> Self {
|
2019-02-24 05:15:37 +01:00
|
|
|
IntervalActor { server: server }
|
2019-02-22 07:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define new events here
|
|
|
|
fn purge_tombstones(&mut self) {
|
|
|
|
// Make a purge request ...
|
|
|
|
let pe = PurgeEvent::new();
|
|
|
|
self.server.do_send(pe)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Actor for IntervalActor {
|
|
|
|
type Context = actix::Context<Self>;
|
|
|
|
|
|
|
|
fn started(&mut self, ctx: &mut Self::Context) {
|
|
|
|
ctx.run_interval(Duration::from_secs(PURGE_TIMEOUT), move |act, _ctx| {
|
|
|
|
act.purge_tombstones();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|