Tasks 7.1–7.3, 7.5 (+7.4 pacing; Retry-After-duration backoff noted as remaining). Resolves the activities.owner_id open question. Schema (design decision from the open question): - activities.owner_id nullable + check constraint enforcing exactly one of (owner_id, remote_actor_iri) — the follows pattern again. - remote_published_at carries the origin's publish time for the §8 feed sort; index on remote_actor_iri for the feed join. - Compiler-audited fallout: notification fan-out, the Note object dispatcher, and the activity detail loader explicitly skip/404 remote rows (their canonical page is the origin; feed links there). Every other surface joins users on owner_id and excludes remote rows structurally. Ingestion: - federation-ingest.server.ts: parseOutboxItem targets exactly our own outgoing Create(Note) shape (PropertyValue stats, first-paragraph name, audience from to/cc); unknown items skipped, never fatal. - ingestRemoteActivities: replay-safe via unique remote_origin_iri, conflict-streak early exit (outboxes are newest-first). - pollRemoteActor: signed fetch (Authorized Fetch via a local follower's key), outbox resolution via remote_actors cache with actor-doc fallback (which refreshes the cache), 1 req/5 s per-host pacing, last_polled_at stamping. Network + pacing injectable. Jobs: poll-remote-actor (per-actor; the §4 Accept listener already enqueues it as the first poll) + poll-remote-outboxes (5-min cron sweep over accepted remote follows not polled within the hour). Tests: parse-shape units; integration suite for ingestion provenance, audience→visibility mirroring, replay safety, the DB author invariant, poll flow (actor-doc → collection → page), signer requirement, and due-polling selection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
26 lines
813 B
TypeScript
26 lines
813 B
TypeScript
import type { JobDefinition } from "@trails-cool/jobs";
|
|
import { pollRemoteActor } from "../lib/federation-ingest.server.ts";
|
|
import { logger } from "../lib/logger.server.ts";
|
|
|
|
interface PollPayload {
|
|
actorIri?: string;
|
|
}
|
|
|
|
/**
|
|
* Poll one remote trails actor's outbox (spec §7). Enqueued by the
|
|
* inbox Accept(Follow) listener (first poll, 7.5) and fanned out by
|
|
* the poll-remote-outboxes cron sweep (7.1).
|
|
*/
|
|
export const pollRemoteActorJob: JobDefinition = {
|
|
name: "poll-remote-actor",
|
|
retryLimit: 2,
|
|
expireInSeconds: 120,
|
|
async handler(jobs) {
|
|
for (const job of jobs) {
|
|
const { actorIri } = (job.data ?? {}) as PollPayload;
|
|
if (!actorIri) continue;
|
|
const result = await pollRemoteActor(actorIri);
|
|
logger.info({ actorIri, result }, "poll-remote-actor");
|
|
}
|
|
},
|
|
};
|