@@ -15,6 +15,33 @@ use std::sync::Arc;
15
15
use std:: time:: Duration ;
16
16
use std:: { env, thread} ;
17
17
18
+ fn start_registry_watcher ( pool : Pool , build_queue : Arc < BuildQueue > ) -> Result < ( ) , Error > {
19
+ thread:: Builder :: new ( )
20
+ . name ( "registry index reader" . to_string ( ) )
21
+ . spawn ( move || {
22
+ // space this out to prevent it from clashing against the queue-builder thread on launch
23
+ thread:: sleep ( Duration :: from_secs ( 30 ) ) ;
24
+ loop {
25
+ let opts = opts ( ) ;
26
+ let mut doc_builder = DocBuilder :: new ( opts, pool. clone ( ) , build_queue. clone ( ) ) ;
27
+
28
+ if doc_builder. is_locked ( ) {
29
+ debug ! ( "Lock file exists, skipping checking new crates" ) ;
30
+ } else {
31
+ debug ! ( "Checking new crates" ) ;
32
+ match doc_builder. get_new_crates ( ) {
33
+ Ok ( n) => debug ! ( "{} crates added to queue" , n) ,
34
+ Err ( e) => error ! ( "Failed to get new crates: {}" , e) ,
35
+ }
36
+ }
37
+
38
+ thread:: sleep ( Duration :: from_secs ( 60 ) ) ;
39
+ }
40
+ } ) ?;
41
+
42
+ Ok ( ( ) )
43
+ }
44
+
18
45
pub fn start_daemon (
19
46
config : Arc < Config > ,
20
47
db : Pool ,
@@ -37,32 +64,7 @@ pub fn start_daemon(
37
64
38
65
if enable_registry_watcher {
39
66
// check new crates every minute
40
- let cloned_db = db. clone ( ) ;
41
- let cloned_build_queue = build_queue. clone ( ) ;
42
- thread:: Builder :: new ( )
43
- . name ( "registry index reader" . to_string ( ) )
44
- . spawn ( move || {
45
- // space this out to prevent it from clashing against the queue-builder thread on launch
46
- thread:: sleep ( Duration :: from_secs ( 30 ) ) ;
47
- loop {
48
- let opts = opts ( ) ;
49
- let mut doc_builder =
50
- DocBuilder :: new ( opts, cloned_db. clone ( ) , cloned_build_queue. clone ( ) ) ;
51
-
52
- if doc_builder. is_locked ( ) {
53
- debug ! ( "Lock file exists, skipping checking new crates" ) ;
54
- } else {
55
- debug ! ( "Checking new crates" ) ;
56
- match doc_builder. get_new_crates ( ) {
57
- Ok ( n) => debug ! ( "{} crates added to queue" , n) ,
58
- Err ( e) => error ! ( "Failed to get new crates: {}" , e) ,
59
- }
60
- }
61
-
62
- thread:: sleep ( Duration :: from_secs ( 60 ) ) ;
63
- }
64
- } )
65
- . unwrap ( ) ;
67
+ start_registry_watcher ( db. clone ( ) , build_queue. clone ( ) ) ?;
66
68
}
67
69
68
70
// build new crates every minute
0 commit comments