Skip to content

Commit

Permalink
improve logging and fix interval bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amirRamirfatahi committed Feb 4, 2025
1 parent c7feac8 commit 37b8c07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/db/graph/queries/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,6 @@ pub fn get_next_homeservers(limit: i8, interval: u64) -> Query {
RETURN COLLECT(hs) as homeservers
",
)
.param("interval", (interval as i64) * 1000)
.param("interval", interval as i64)
.param("limit", limit)
}
10 changes: 4 additions & 6 deletions src/events/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ impl EventProcessor {
let processor_semaphore = Arc::new(Semaphore::new(self.max_processors));

loop {
info!("Fetching events...");
info!("Fetching homeservers...");
let homeservers = Homeserver::get_next_homeservers(
processor_semaphore.available_permits() as i8,
self.sleep,
)
.await?;
for mut homeserver in homeservers {
info!("Starting task for processing homeserver: {:?}", homeserver);
let permit = processor_semaphore.clone().acquire_owned().await?;
homeserver.last_polled_at = chrono::Utc::now().timestamp_millis();
homeserver.save().await?;
let mut processor = self.clone();
tokio::spawn(async move {
info!("Processing events for homeserver: {:?}", homeserver);
if let Err(e) = processor.run(homeserver).await {
error!("Uncaught error occurred while processing events: {:?}", e);
}
Expand All @@ -90,11 +92,7 @@ impl EventProcessor {
}

pub async fn run(&mut self, homeserver: Homeserver) -> Result<(), DynError> {
let lines = {
self.poll_events(homeserver.clone())
.await
.unwrap_or_default()
};
let lines = self.poll_events(homeserver.clone()).await?;
if let Some(lines) = lines {
self.process_event_lines(homeserver, lines).await?;
};
Expand Down

0 comments on commit 37b8c07

Please sign in to comment.