11use crate :: error:: Result ;
2- use crate :: repositories:: { GitHub , GitLab } ;
2+ use crate :: repositories:: { GitHub , GitLab , RateLimitReached } ;
33use crate :: utils:: MetadataPackage ;
44use crate :: { db:: Pool , Config } ;
55use chrono:: { DateTime , Utc } ;
@@ -128,7 +128,7 @@ impl RepositoryStatsUpdater {
128128
129129 pub fn update_all_crates ( & self ) -> Result < ( ) > {
130130 let mut conn = self . pool . get ( ) ?;
131- for updater in & self . updaters {
131+ ' updaters : for updater in & self . updaters {
132132 info ! ( "started updating `{}` repositories stats" , updater. host( ) ) ;
133133
134134 let needs_update = conn
@@ -152,7 +152,19 @@ impl RepositoryStatsUpdater {
152152 // FIXME: The collect can be avoided if we use Itertools::chunks:
153153 // https://docs.rs/itertools/0.10.0/itertools/trait.Itertools.html#method.chunks.
154154 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+ } ;
156168 for node in res. missing {
157169 self . delete_repository ( & mut conn, & node, updater. host ( ) ) ?;
158170 }
0 commit comments