Skip to content

Commit 845ac73

Browse files
committed
Remove the worker dyno
We're paying for a dyno that spends 90% of its time sleeping. A repeating task like this is better handled by a cron-like tool (heroku scheduler in our case), especially for something non-critical like updating download counts.
1 parent 7ca518d commit 845ac73

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

Procfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
web: bin/diesel migration run && bin/start-nginx ./target/release/server
2-
worker: ./target/release/update-downloads daemon 300
32
background_worker: ./target/release/background-worker

src/bin/update-downloads.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,17 @@ use cargo_registry::{
77
db,
88
models::VersionDownload,
99
schema::{crate_downloads, crates, metadata, version_downloads, versions},
10+
util::CargoResult,
1011
};
11-
use std::{env, thread, time::Duration};
1212

1313
use diesel::prelude::*;
1414

1515
static LIMIT: i64 = 1000;
1616

17-
fn main() {
18-
let daemon = env::args().nth(1).as_ref().map(|s| &s[..]) == Some("daemon");
19-
let sleep = env::args().nth(2).map(|s| s.parse().unwrap());
20-
loop {
21-
let conn = db::connect_now().unwrap();
22-
update(&conn).unwrap();
23-
drop(conn);
24-
if daemon {
25-
thread::sleep(Duration::new(sleep.unwrap(), 0));
26-
} else {
27-
break;
28-
}
29-
}
17+
fn main() -> CargoResult<()> {
18+
let conn = db::connect_now()?;
19+
update(&conn)?;
20+
Ok(())
3021
}
3122

3223
fn update(conn: &PgConnection) -> QueryResult<()> {

0 commit comments

Comments
 (0)