@@ -7,44 +7,36 @@ use std::thread;
7
7
use std:: time:: Duration ;
8
8
9
9
const DAY : Duration = Duration :: from_secs ( 60 * 60 * 24 ) ;
10
- // The tuple is composed of:
11
- // - job name
12
- // - interval between executions
13
- // - function to execute at specified intervals
14
- type JobDescription = ( & ' static str , Duration , fn ( Arc < Data > ) -> Fallible < ( ) > ) ;
15
-
16
- lazy_static ! {
17
- static ref JOBS : Vec <JobDescription > = {
18
- let mut jobs = Vec :: new( ) ;
19
- jobs. push( (
20
- "crate list update" ,
21
- DAY ,
22
- update_crates as fn ( Arc <Data >) -> Fallible <( ) >,
23
- ) ) ;
24
-
25
- jobs
26
- } ;
10
+ struct JobDescription {
11
+ name : & ' static str ,
12
+ interval : Duration ,
13
+ exec : fn ( Arc < Data > ) -> Fallible < ( ) > ,
27
14
}
28
15
16
+ static JOBS : & [ JobDescription ] = & [ JobDescription {
17
+ name : "crates lists update" ,
18
+ interval : DAY ,
19
+ exec : update_crates as fn ( Arc < Data > ) -> Fallible < ( ) > ,
20
+ } ] ;
21
+
29
22
pub fn spawn ( data : Data ) {
30
23
let data = Arc :: new ( data) ;
31
- for job in JOBS . iter ( ) {
32
- let ( name, timer, exec) = job;
24
+ for job in JOBS {
33
25
// needed to make the borrowck happy
34
26
let data = Arc :: clone ( & data) ;
35
27
36
28
thread:: spawn ( move || loop {
37
- let result = exec ( Arc :: clone ( & data) ) ;
29
+ let result = ( job . exec ) ( Arc :: clone ( & data) ) ;
38
30
if let Err ( e) = result {
39
31
utils:: report_failure ( & e) ;
40
32
}
41
33
42
34
info ! (
43
35
"the {} thread will be respawned in {}s" ,
44
- name,
45
- timer . as_secs( )
36
+ job . name,
37
+ job . interval . as_secs( )
46
38
) ;
47
- thread:: sleep ( * timer ) ;
39
+ thread:: sleep ( job . interval ) ;
48
40
} ) ;
49
41
}
50
42
}
0 commit comments