1
- use crate :: {
2
- docbuilder:: RustwideBuilder ,
3
- utils:: { pubsubhubbub, report_error} ,
4
- BuildQueue ,
5
- } ;
6
- use anyhow:: { Context , Error } ;
1
+ use crate :: { docbuilder:: RustwideBuilder , utils:: report_error, BuildQueue } ;
2
+ use anyhow:: Error ;
7
3
use log:: { debug, error, info, warn} ;
8
4
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
9
5
use std:: sync:: Arc ;
@@ -23,81 +19,47 @@ pub fn queue_builder(
23
19
EmptyQueue ,
24
20
/// The builder has just seen the lock file.
25
21
Locked ,
26
- /// The builder has just finished building a crate. The enclosed count is the number of
27
- /// crates built since the caches have been refreshed.
28
- QueueInProgress ( usize ) ,
22
+ /// The builder has started (or just finished) building a crate.
23
+ QueueInProgress ,
29
24
}
30
25
31
26
let mut status = BuilderState :: Fresh ;
32
27
33
28
loop {
34
- if !status . is_in_progress ( ) {
29
+ if !matches ! ( status , BuilderState :: QueueInProgress ) {
35
30
thread:: sleep ( Duration :: from_secs ( 60 ) ) ;
36
31
}
37
32
38
33
// check lock file
39
34
if build_queue. is_locked ( ) {
40
- warn ! ( "Lock file exits , skipping building new crates" ) ;
35
+ warn ! ( "Lock file exists , skipping building new crates" ) ;
41
36
status = BuilderState :: Locked ;
42
37
continue ;
43
38
}
44
39
45
- if status. count ( ) >= 10 {
46
- // periodically, ping the hubs
47
- debug ! ( "10 builds in a row; pinging pubsubhubhub" ) ;
48
- status = BuilderState :: QueueInProgress ( 0 ) ;
49
-
50
- match pubsubhubbub:: ping_hubs ( ) . context ( "Failed to ping hub" ) {
51
- Err ( e) => report_error ( & e) ,
52
- Ok ( n) => debug ! ( "Succesfully pinged {} hubs" , n) ,
53
- }
54
- }
55
-
56
40
// Only build crates if there are any to build
57
41
debug ! ( "Checking build queue" ) ;
58
- match build_queue
59
- . pending_count ( )
60
- . context ( "Failed to read the number of crates in the queue" )
61
- {
42
+ match build_queue. pending_count ( ) {
62
43
Err ( e) => {
63
- report_error ( & e) ;
44
+ report_error ( & e. context ( "Failed to read the number of crates in the queue" ) ) ;
64
45
continue ;
65
46
}
66
47
67
48
Ok ( 0 ) => {
68
- if status. count ( ) > 0 {
69
- // ping the hubs before continuing
70
- match pubsubhubbub:: ping_hubs ( ) . context ( "Failed to ping hub" ) {
71
- Err ( e) => report_error ( & e) ,
72
- Ok ( n) => debug ! ( "Succesfully pinged {} hubs" , n) ,
73
- }
74
- }
75
49
debug ! ( "Queue is empty, going back to sleep" ) ;
76
50
status = BuilderState :: EmptyQueue ;
77
51
continue ;
78
52
}
79
53
80
- Ok ( queue_count) => {
81
- info ! (
82
- "Starting build with {} crates in queue (currently on a {} crate streak)" ,
83
- queue_count,
84
- status. count( )
85
- ) ;
86
- }
54
+ Ok ( queue_count) => info ! ( "Starting build with {} crates in queue" , queue_count) ,
87
55
}
88
56
57
+ status = BuilderState :: QueueInProgress ;
58
+
89
59
// If a panic occurs while building a crate, lock the queue until an admin has a chance to look at it.
90
60
let res = catch_unwind ( AssertUnwindSafe ( || {
91
- match build_queue
92
- . build_next_queue_package ( & mut builder)
93
- . context ( "Failed to build crate from queue" )
94
- {
95
- Err ( e) => report_error ( & e) ,
96
- Ok ( crate_built) => {
97
- if crate_built {
98
- status. increment ( ) ;
99
- }
100
- }
61
+ if let Err ( e) = build_queue. build_next_queue_package ( & mut builder) {
62
+ report_error ( & e. context ( "Failed to build crate from queue" ) ) ;
101
63
}
102
64
} ) ) ;
103
65
@@ -107,21 +69,4 @@ pub fn queue_builder(
107
69
build_queue. lock ( ) . expect ( "failed to lock queue" ) ;
108
70
}
109
71
}
110
-
111
- impl BuilderState {
112
- fn count ( & self ) -> usize {
113
- match * self {
114
- BuilderState :: QueueInProgress ( n) => n,
115
- _ => 0 ,
116
- }
117
- }
118
-
119
- fn is_in_progress ( & self ) -> bool {
120
- matches ! ( * self , BuilderState :: QueueInProgress ( _) )
121
- }
122
-
123
- fn increment ( & mut self ) {
124
- * self = BuilderState :: QueueInProgress ( self . count ( ) + 1 ) ;
125
- }
126
- }
127
72
}
0 commit comments