@@ -196,21 +196,29 @@ pub fn start_daemon(config: Arc<Config>, db: Pool) -> Result<(), Error> {
196
196
197
197
// update release activity everyday at 23:55
198
198
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
+ ) ?;
207
211
208
212
// update github stats every 6 hours
209
213
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
+ ) ?;
214
222
215
223
// TODO: update ssl certificate every 3 months
216
224
@@ -221,14 +229,14 @@ pub fn start_daemon(config: Arc<Config>, db: Pool) -> Result<(), Error> {
221
229
Ok ( ( ) )
222
230
}
223
231
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 >
225
233
where
226
234
F : Fn ( ) -> Result < ( ) , Error > + Send + ' static ,
227
235
{
228
236
thread:: Builder :: new ( )
229
237
. name ( name. into ( ) )
230
238
. spawn ( move || loop {
231
- thread:: sleep ( Duration :: from_secs ( interval) ) ;
239
+ thread:: sleep ( interval) ;
232
240
if let Err ( err) = exec ( ) {
233
241
error ! ( "failed to run cron '{}': {:?}" , name, err) ;
234
242
}
0 commit comments