House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
Build / Build (push) Successful in 30s
- Services, controllers and jobs take their dependencies through primary constructors and use them directly; where a method already named a local after a dependency, the dependency takes its type's name. - Every async method takes a CancellationToken last and passes it down to MongoDB, HTTP and the job queue. The setup claim is still given back when a request is cancelled. - The federation and media options are read through IOptionsMonitor. - The Mastodon entities keep sending "" for empty strings, and every model field where null means something says so. - The inbox's 503 with Retry-After, which other servers retry, is the one server error left, and says why. - Arasaka.HouseRules.Analyzers checks all of this in every build, here and in PrivaPub.ClientModels as decePubClient builds it. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -20,27 +20,17 @@ namespace PrivaPub.Federation.Inbox
|
||||
Task Handle(JsonNode activity, ForeignAvatar actor, CancellationToken token);
|
||||
}
|
||||
|
||||
public class InboxProcessor : IJobHandler
|
||||
public class InboxProcessor(
|
||||
IRemoteActorService remoteActors,
|
||||
IEnumerable<IActivityHandler> handlers,
|
||||
ILogger<InboxProcessor> logger,
|
||||
IInteractionLedger ledger = default,
|
||||
ILocalActorService localActors = default,
|
||||
Microsoft.Extensions.Options.IOptionsMonitor<Infrastructure.Http.FederationOptions> federation = default) : IJobHandler
|
||||
{
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly IReadOnlyDictionary<string, IActivityHandler> _handlers;
|
||||
readonly ILogger<InboxProcessor> _logger;
|
||||
readonly IInteractionLedger _ledger;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IReadOnlyDictionary<string, IActivityHandler> _handlers = handlers.ToDictionary(h => h.Type, StringComparer.Ordinal);
|
||||
readonly int _concurrency = Math.Max(1, federation?.CurrentValue.InboxConcurrency ?? 8);
|
||||
|
||||
readonly int _concurrency;
|
||||
|
||||
public InboxProcessor(IRemoteActorService remoteActors, IEnumerable<IActivityHandler> handlers, ILogger<InboxProcessor> logger,
|
||||
IInteractionLedger ledger = default, ILocalActorService localActors = default,
|
||||
Microsoft.Extensions.Options.IOptions<Infrastructure.Http.FederationOptions> federation = default)
|
||||
{
|
||||
_concurrency = Math.Max(1, federation?.Value.InboxConcurrency ?? 8);
|
||||
_localActors = localActors;
|
||||
_remoteActors = remoteActors;
|
||||
_handlers = handlers.ToDictionary(h => h.Type, StringComparer.Ordinal);
|
||||
_logger = logger;
|
||||
_ledger = ledger;
|
||||
}
|
||||
|
||||
public JobKind Kind => JobKind.ProcessInbox;
|
||||
public int Concurrency => _concurrency;
|
||||
@@ -59,7 +49,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
|
||||
var actor = await _remoteActors.GetActor(payload.ActorURI, refresh: false, token);
|
||||
var actor = await remoteActors.GetActor(payload.ActorURI, refresh: false, token);
|
||||
if (actor == default)
|
||||
{
|
||||
Record(job, payload, activity, type, started, new ArrivalVerdict(), Interactions.Deferred, "actor-unavailable");
|
||||
@@ -73,10 +63,10 @@ namespace PrivaPub.Federation.Inbox
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
if (payload.ForwardedBy != default && Forwarded.NamesUnknownKey(activity, actor))
|
||||
actor = await _remoteActors.GetActor(actor.ActorURI, refresh: true, token) ?? actor;
|
||||
actor = await remoteActors.GetActor(actor.ActorURI, refresh: true, token) ?? actor;
|
||||
if (payload.ForwardedBy != default && !Forwarded.Proven(activity, actor))
|
||||
{
|
||||
var (confirmed, drop) = await Forwarded.Confirm(activity, type, actor.ActorURI, _remoteActors, token);
|
||||
var (confirmed, drop) = await Forwarded.Confirm(activity, type, actor.ActorURI, remoteActors, token);
|
||||
if (drop != default)
|
||||
{
|
||||
Record(job, payload, activity, type, started, new ArrivalVerdict(), Interactions.Dropped, drop);
|
||||
@@ -91,7 +81,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
Arrival.Current = arrival;
|
||||
try
|
||||
{
|
||||
await LocalReferences.Canonicalise(activity, _localActors?.BaseAddress, token);
|
||||
await LocalReferences.Canonicalise(activity, localActors?.BaseAddress, token);
|
||||
await handler.Handle(activity, actor, token);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
@@ -104,16 +94,16 @@ namespace PrivaPub.Federation.Inbox
|
||||
Arrival.Current = default;
|
||||
}
|
||||
Record(job, payload, activity, type, started, arrival.Verdict, default, default);
|
||||
_logger.LogInformation("Processed {Type} {Id} from {Actor}", type, Id(activity), actor.ActorURI);
|
||||
logger.LogInformation("Processed {Type} {Id} from {Actor}", type, Id(activity), actor.ActorURI);
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
|
||||
void Record(Job job, InboxPayload payload, JsonNode activity, string type, long started, ArrivalVerdict verdict, string outcome, string reason)
|
||||
{
|
||||
if (_ledger == default || payload == default)
|
||||
if (ledger == default || payload == default)
|
||||
return;
|
||||
var embedded = activity?["object"] as JsonObject;
|
||||
_ledger.Record(new InteractionEvent
|
||||
ledger.Record(new InteractionEvent
|
||||
{
|
||||
Channel = Interactions.In,
|
||||
Host = Interactions.HostOf(payload.ActorURI),
|
||||
|
||||
Reference in new issue
Block a user