[backend/federation] Retry inbox jobs with exponential backoff (ISH-499)

This should cover most transient failures. If one is missing, we can add it later.
This commit is contained in:
Laura Hausmann 2024-09-24 00:36:13 +02:00
parent 0c39101046
commit d1721d71c2
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -37,6 +37,30 @@ public class InboxQueue(int parallelism)
else else
logger.LogDebug("Refusing to process activity {id}: Instance is blocked ({uri})", job.Id, e.Uri); logger.LogDebug("Refusing to process activity {id}: Instance is blocked ({uri})", job.Id, e.Uri);
} }
catch (Exception e) when (e is not GracefulException)
{
if (job.RetryCount++ < 4)
{
var jitter = TimeSpan.FromSeconds(new Random().Next(0, 60));
var baseDelay = TimeSpan.FromMinutes(1);
var maxBackoff = TimeSpan.FromHours(8);
var backoff = (Math.Pow(2, job.RetryCount) - 1) * baseDelay;
if (backoff > maxBackoff)
backoff = maxBackoff;
backoff += jitter;
job.ExceptionMessage = e.Message;
job.ExceptionSource = e.Source;
job.StackTrace = e.StackTrace;
job.Exception = e.ToString();
job.DelayedUntil = DateTime.UtcNow + backoff;
job.Status = Job.JobStatus.Delayed;
}
else
{
throw;
}
}
} }
} }