1
1
use crate :: error:: Result ;
2
- use crate :: repositories:: { GitHub , GitLab } ;
2
+ use crate :: repositories:: { GitHub , GitLab , RateLimitReached } ;
3
3
use crate :: utils:: MetadataPackage ;
4
4
use crate :: { db:: Pool , Config } ;
5
5
use chrono:: { DateTime , Utc } ;
@@ -128,7 +128,7 @@ impl RepositoryStatsUpdater {
128
128
129
129
pub fn update_all_crates ( & self ) -> Result < ( ) > {
130
130
let mut conn = self . pool . get ( ) ?;
131
- for updater in & self . updaters {
131
+ ' updaters : for updater in & self . updaters {
132
132
info ! ( "started updating `{}` repositories stats" , updater. host( ) ) ;
133
133
134
134
let needs_update = conn
@@ -152,7 +152,19 @@ impl RepositoryStatsUpdater {
152
152
// FIXME: The collect can be avoided if we use Itertools::chunks:
153
153
// https://docs.rs/itertools/0.10.0/itertools/trait.Itertools.html#method.chunks.
154
154
for chunk in needs_update. chunks ( updater. chunk_size ( ) ) {
155
- let res = updater. fetch_repositories ( chunk) ?;
155
+ let res = match updater. fetch_repositories ( chunk) {
156
+ Ok ( r) => r,
157
+ Err ( err) => {
158
+ if err. downcast_ref :: < RateLimitReached > ( ) . is_some ( ) {
159
+ warn ! (
160
+ "rate limit reached, skipping the `{}` repository stats updater" ,
161
+ updater. host( )
162
+ ) ;
163
+ continue ' updaters;
164
+ }
165
+ return Err ( err) ;
166
+ }
167
+ } ;
156
168
for node in res. missing {
157
169
self . delete_repository ( & mut conn, & node, updater. host ( ) ) ?;
158
170
}
0 commit comments