Skip to content

Commit

Permalink
Prepare for looping eviction calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Apr 8, 2024
1 parent b33c522 commit bab65ef
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions rust/src/rendezvous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ use headers::{
IfMatch, IfNoneMatch, Pragma,
};
use http::{header::ETAG, HeaderMap, Response, StatusCode, Uri};
use log::info;
use mime::Mime;
use pyo3::{
exceptions::PyValueError, pyclass, pymethods, types::PyModule, PyAny, PyResult, Python,
exceptions::PyValueError, pyclass, pymethods, types::PyModule, Py, PyAny, PyResult, Python,
};
use ulid::Ulid;

Expand Down Expand Up @@ -67,7 +68,7 @@ struct RendezVousHandler {
#[pymethods]
impl RendezVousHandler {
#[new]
fn new(homeserver: &PyAny) -> PyResult<Self> {
fn new(py: Python<'_>, homeserver: &PyAny) -> PyResult<Py<Self>> {
let base: String = homeserver
.getattr("config")?
.getattr("server")?
Expand All @@ -78,10 +79,26 @@ impl RendezVousHandler {
))
.map_err(|_| PyValueError::new_err("Invalid base URI"))?;

Ok(Self {
base,
sessions: HashMap::new(),
})
// Construct a Python object so that we can get a reference to the
// evict method and schedule it to run.
let self_ = Py::new(
py,
Self {
base,
sessions: HashMap::new(),
},
)?;

let evict = self_.getattr(py, "_evict")?;
homeserver
.call_method0("get_clock")?
.call_method("looping_call", (evict, 500), None)?;

Ok(self_)
}

fn _evict(&mut self) {
info!("Evicting sessions");
}

fn handle_post(&mut self, twisted_request: &PyAny) -> PyResult<()> {
Expand Down

0 comments on commit bab65ef

Please sign in to comment.