Skip to content

Commit e31147f

Browse files
committed
Survive transient errors in scanner and processor loops
A single failed GitHub request in the scanner loop (e.g. a transient 401 from an expired installation token) previously propagated out of the task and terminated the entire rfd-processor process. The same applied to a failed database query when fetching the job batch in the processor loop. Log these errors and retry on the next tick instead. Job creation is idempotent (unique on sha + rfd) and the scanner re-enumerates all RFDs every pass, so skipped iterations are recovered on the next successful scan.
1 parent c5c58da commit e31147f

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

rfd-processor/src/processor.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,24 @@ pub async fn processor(ctx: Arc<Context>) -> Result<(), JobError> {
3939

4040
loop {
4141
if ctx.processor.enabled {
42-
let jobs = JobStore::list(
42+
// Errors fetching the job list (i.e. transient database failures) must not take down
43+
// the processor. Skip this batch and try again on the next tick
44+
let jobs = match JobStore::list(
4345
&ctx.db.storage,
4446
vec![JobFilter::default()
4547
.processed(Some(false))
4648
.started(Some(false))],
4749
&pagination,
4850
)
49-
.await?;
51+
.await
52+
{
53+
Ok(jobs) => jobs,
54+
Err(err) => {
55+
tracing::error!(?err, "Failed to fetch job batch");
56+
interval.tick().await;
57+
continue;
58+
}
59+
};
5060

5161
tracing::info!(jobs = ?jobs.iter().map(|job| job.id).collect::<Vec<_>>(), "Spawning jobs");
5262

rfd-processor/src/scanner.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,36 @@ pub async fn scanner(ctx: Arc<Context>) -> Result<(), ScannerError> {
2525

2626
loop {
2727
if ctx.scanner.enabled {
28-
let updates = ctx
28+
// Errors reaching GitHub (including transient auth and rate limit failures) must not
29+
// take down the scanner. Skip this scan and try again on the next tick
30+
match ctx
2931
.github
3032
.repository
3133
.get_rfd_sync_updates(&ctx.github.client)
32-
.await?;
33-
34-
for update in updates {
35-
match JobStore::upsert(&ctx.db.storage, update.clone().into_job()).await {
36-
Ok(job) => tracing::trace!(?job.id, "Added job to the queue"),
37-
Err(err) => {
38-
match err {
39-
StoreError::Conflict => {
40-
// Nothing to do here, we expect uniqueness conflicts. It is expected
41-
// that the scanner picks ups redundant jobs for RFDs that have not
42-
// changed since the last scan
43-
}
44-
err => {
45-
tracing::warn!(?err, ?update, "Failed to add job")
34+
.await
35+
{
36+
Ok(updates) => {
37+
for update in updates {
38+
match JobStore::upsert(&ctx.db.storage, update.clone().into_job()).await {
39+
Ok(job) => tracing::trace!(?job.id, "Added job to the queue"),
40+
Err(err) => {
41+
match err {
42+
StoreError::Conflict => {
43+
// Nothing to do here, we expect uniqueness conflicts. It is expected
44+
// that the scanner picks ups redundant jobs for RFDs that have not
45+
// changed since the last scan
46+
}
47+
err => {
48+
tracing::warn!(?err, ?update, "Failed to add job")
49+
}
50+
}
4651
}
4752
}
4853
}
4954
}
55+
Err(err) => {
56+
tracing::error!(?err, "Failed to fetch RFD updates from GitHub");
57+
}
5058
}
5159
}
5260

0 commit comments

Comments
 (0)