[backend/federation] Skip dead instances in deliver queue
This commit is contained in:
parent
01b7135208
commit
489941adcc
3 changed files with 34 additions and 9 deletions
|
@ -37,4 +37,12 @@ public class FederationControlService(
|
|||
return await db.BlockedInstances.AnyAsync(p => finalHosts.Any(host => host == p.Host ||
|
||||
host.EndsWith("." + p.Host)));
|
||||
}
|
||||
|
||||
public async Task<bool> ShouldSkipAsync(string host)
|
||||
{
|
||||
return await db.Instances.AnyAsync(p => p.Host == host.ToLowerInvariant() &&
|
||||
((p.IsNotResponding &&
|
||||
p.LastCommunicatedAt < DateTime.UtcNow - TimeSpan.FromDays(7)) ||
|
||||
p.IsSuspended));
|
||||
}
|
||||
}
|
|
@ -34,6 +34,12 @@ public class DeliverQueue
|
|||
return;
|
||||
}
|
||||
|
||||
if (await fedCtrl.ShouldSkipAsync(job.RecipientHost))
|
||||
{
|
||||
logger.LogDebug("fedCtrl.ShouldSkipAsync returned true, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogDebug("Delivering activity to: {uri}", job.InboxUrl);
|
||||
|
||||
var key = await cache.FetchAsync($"userPrivateKey:{job.UserId}", TimeSpan.FromMinutes(60), async () =>
|
||||
|
@ -53,8 +59,8 @@ public class DeliverQueue
|
|||
_ = followup.ExecuteTask("UpdateInstanceMetadata", async provider =>
|
||||
{
|
||||
var instanceSvc = provider.GetRequiredService<InstanceService>();
|
||||
var webDomain = new Uri(job.InboxUrl).Host;
|
||||
await instanceSvc.UpdateInstanceStatusAsync(job.RecipientHost, webDomain, (int)response.StatusCode);
|
||||
await instanceSvc.UpdateInstanceStatusAsync(job.RecipientHost, new Uri(job.InboxUrl).Host,
|
||||
(int)response.StatusCode, response.IsSuccessStatusCode);
|
||||
});
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
|
|
@ -78,21 +78,32 @@ public class InstanceService(DatabaseContext db, HttpClient httpClient)
|
|||
}
|
||||
}
|
||||
|
||||
public async Task UpdateInstanceStatusAsync(string host, string webDomain, int? statusCode = null)
|
||||
public async Task UpdateInstanceStatusAsync(string host, string webDomain)
|
||||
{
|
||||
var instance = await GetUpdatedInstanceMetadataAsync(host, webDomain);
|
||||
|
||||
if (statusCode != null)
|
||||
instance.LastCommunicatedAt = DateTime.UtcNow;
|
||||
instance.LatestRequestReceivedAt = DateTime.UtcNow;
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateInstanceStatusAsync(string host, string webDomain, int statusCode, bool notResponding)
|
||||
{
|
||||
var instance = await GetUpdatedInstanceMetadataAsync(host, webDomain);
|
||||
|
||||
instance.LatestStatus = statusCode;
|
||||
instance.LatestRequestSentAt = DateTime.UtcNow;
|
||||
|
||||
if (notResponding)
|
||||
{
|
||||
instance.IsNotResponding = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.LatestRequestReceivedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
instance.IsNotResponding = false;
|
||||
instance.LastCommunicatedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue