Add background processing
@@ -11,8 +11,8 @@ use tower::{Service, ServiceExt};
use tracing as log;
use tracing::Instrument;
use triagebot::{db, github, handlers::Context, notification_listing, payload, EventName};
-// use std::{time::Duration, thread};
-// use tokio::task;
+use std::{time::Duration, thread};
+use tokio::task;
async fn handle_agenda_request(req: String) -> anyhow::Result<String> {
if req == "/agenda/lang/triage" {
@@ -239,19 +239,17 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
.await
.context("database migrations")?;
- db::run_scheduled_events(&*pool.get().await)
- .await
- .context("database scheduled_events")?;
+ task::spawn(async move {
+ let pool = db::ClientPool::new();
- // task::spawn(async move {
- // loop {
- // thread::sleep(Duration::from_secs(60)); // every one minute
+ loop {
+ thread::sleep(Duration::from_secs(60)); // every one minute
- // db::run_scheduled_events(&*pool.get().await)
- // .await
- // .context("database scheduled_events")?;
- // }
- // });
+ db::run_scheduled_events(&*pool.get().await)
+ .await
+ .context("database scheduled_events").unwrap();
+ }
+ });
let client = Client::new();
let gh = github::GithubClient::new_with_default_token(client.clone());
