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
|
|
|
|
2019-09-04 03:06:37 +02:00
|
|
|
use crate::actors::v1::QueryServerV1;
|
2019-04-18 03:28:33 +02:00
|
|
|
use crate::constants::PURGE_TIMEOUT;
|
|
|
|
use crate::event::{PurgeRecycledEvent, PurgeTombstoneEvent};
|
2019-02-22 07:15:48 +01:00
|
|
|
|
|
|
|
pub struct IntervalActor {
|
|
|
|
// Store any addresses we require
|
2019-03-01 07:15:31 +01:00
|
|
|
server: actix::Addr<QueryServerV1>,
|
2019-02-22 07:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl IntervalActor {
|
2019-03-01 07:15:31 +01:00
|
|
|
pub fn new(server: actix::Addr<QueryServerV1>) -> 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 ...
|
2019-02-25 10:36:53 +01:00
|
|
|
let pe = PurgeTombstoneEvent::new();
|
|
|
|
self.server.do_send(pe)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn purge_recycled(&mut self) {
|
|
|
|
let pe = PurgeRecycledEvent::new();
|
2019-02-22 07:15:48 +01:00
|
|
|
self.server.do_send(pe)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Actor for IntervalActor {
|
|
|
|
type Context = actix::Context<Self>;
|
|
|
|
|
|
|
|
fn started(&mut self, ctx: &mut Self::Context) {
|
2019-07-27 08:54:31 +02:00
|
|
|
// TODO #65: This timeout could be configurable from config?
|
2019-02-25 10:36:53 +01:00
|
|
|
ctx.run_interval(Duration::from_secs(PURGE_TIMEOUT), move |act, _ctx| {
|
|
|
|
act.purge_recycled();
|
|
|
|
});
|
2019-02-22 07:15:48 +01:00
|
|
|
ctx.run_interval(Duration::from_secs(PURGE_TIMEOUT), move |act, _ctx| {
|
|
|
|
act.purge_tombstones();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|