Skip to content

Commit 81c82ef

Browse files
committed
wire up the cron
1 parent e45236b commit 81c82ef

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

site/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ extern crate itertools;
44
pub mod api;
55
pub mod github;
66
pub mod load;
7+
pub mod queue_jobs;
78
pub mod server;
89

910
mod average;
1011
mod benchmark_metadata;
1112
mod comparison;
12-
mod queue_jobs;
1313
mod request_handlers;
1414
mod resources;
1515
mod selector;

site/src/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use parking_lot::RwLock;
33
use site::load;
44
use std::env;
55
use std::sync::Arc;
6+
use tokio::task;
67

78
#[cfg(unix)]
89
#[global_allocator]
@@ -28,6 +29,15 @@ async fn main() {
2829
.ok()
2930
.and_then(|x| x.parse().ok())
3031
.unwrap_or(2346);
32+
let queue_update_interval_seconds = env::var("QUEUE_UPDATE_INTERVAL_SECONDS")
33+
.ok()
34+
.and_then(|x| x.parse().ok())
35+
.unwrap_or(30);
36+
let run_cron_job = env::var("RUN_CRON")
37+
.ok()
38+
.and_then(|x| x.parse().ok())
39+
.unwrap_or(false);
40+
3141
let fut = tokio::task::spawn_blocking(move || {
3242
tokio::task::spawn(async move {
3343
let res = Arc::new(load::SiteCtxt::from_db_url(&db_url).await.unwrap());
@@ -50,7 +60,14 @@ async fn main() {
5060
.fuse();
5161
println!("Starting server with port={:?}", port);
5262

53-
let server = site::server::start(ctxt, port).fuse();
63+
let server = site::server::start(ctxt.clone(), port).fuse();
64+
65+
if run_cron_job {
66+
task::spawn(async move {
67+
site::queue_jobs::cron_enqueue_jobs(ctxt.clone(), queue_update_interval_seconds).await;
68+
});
69+
}
70+
5471
futures::pin_mut!(server);
5572
futures::pin_mut!(fut);
5673
loop {

0 commit comments

Comments
 (0)