Skip to content

Commit 2aec78e

Browse files
pietroalbiniJoshua Nelson
authored andcommitted
daemon: use explicit duration for crons
1 parent 1099fd8 commit 2aec78e

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/utils/daemon.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,29 @@ pub fn start_daemon(config: Arc<Config>, db: Pool) -> Result<(), Error> {
196196

197197
// update release activity everyday at 23:55
198198
let cloned_db = db.clone();
199-
cron("release activity updater", 60, move || {
200-
let now = Utc::now();
201-
if now.hour() == 23 && now.minute() == 55 {
202-
info!("Updating release activity");
203-
update_release_activity(&*cloned_db.get()?)?;
204-
}
205-
Ok(())
206-
})?;
199+
cron(
200+
"release activity updater",
201+
Duration::from_secs(60),
202+
move || {
203+
let now = Utc::now();
204+
if now.hour() == 23 && now.minute() == 55 {
205+
info!("Updating release activity");
206+
update_release_activity(&*cloned_db.get()?)?;
207+
}
208+
Ok(())
209+
},
210+
)?;
207211

208212
// update github stats every 6 hours
209213
let cloned_db = db.clone();
210-
cron("github stats updater", 60 * 60 * 6, move || {
211-
github_updater(&*cloned_db.get()?)?;
212-
Ok(())
213-
})?;
214+
cron(
215+
"github stats updater",
216+
Duration::from_secs(60 * 60 * 6),
217+
move || {
218+
github_updater(&*cloned_db.get()?)?;
219+
Ok(())
220+
},
221+
)?;
214222

215223
// TODO: update ssl certificate every 3 months
216224

@@ -221,14 +229,14 @@ pub fn start_daemon(config: Arc<Config>, db: Pool) -> Result<(), Error> {
221229
Ok(())
222230
}
223231

224-
fn cron<F>(name: &'static str, interval: u64, exec: F) -> Result<(), Error>
232+
fn cron<F>(name: &'static str, interval: Duration, exec: F) -> Result<(), Error>
225233
where
226234
F: Fn() -> Result<(), Error> + Send + 'static,
227235
{
228236
thread::Builder::new()
229237
.name(name.into())
230238
.spawn(move || loop {
231-
thread::sleep(Duration::from_secs(interval));
239+
thread::sleep(interval);
232240
if let Err(err) = exec() {
233241
error!("failed to run cron '{}': {:?}", name, err);
234242
}

0 commit comments

Comments
 (0)