@@ -15,6 +15,33 @@ use std::sync::Arc;
1515use std:: time:: Duration ;
1616use std:: { env, thread} ;
1717
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+
1845pub fn start_daemon (
1946 config : Arc < Config > ,
2047 db : Pool ,
@@ -37,32 +64,7 @@ pub fn start_daemon(
3764
3865 if enable_registry_watcher {
3966 // 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 ( ) ) ?;
6668 }
6769
6870 // build new crates every minute
0 commit comments