feat(intake): pending entries carry the newest receipt's handoff
So the receiving service can look up a handoff it already made before it repeats one (tenant-registry#119). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
This commit is contained in:
1 parent
b4583de691
commit
bf83d0625e
5 files changed
+9
-6
No files matched your search
@@ -82,10 +82,10 @@ func TestIntakeStore(t *testing.T) {
|
||||
if p, _ := h.store.PendingIntake(ctx, 1); len(p) != 1 {
|
||||
t.Fatalf("limit: %+v", p)
|
||||
}
|
||||
if _, err := receipt(s1.ID, store.IntakeDelivered, ""); err != nil {
|
||||
if _, err := h.store.AddIntakeReceipt(ctx, store.IntakeReceipt{EntryID: s1.ID, Status: store.IntakeDelivered, HandoffID: "h-7", By: "w", At: at}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p, _ := h.store.PendingIntake(ctx, 10); p[1].Status != store.IntakeDelivered {
|
||||
if p, _ := h.store.PendingIntake(ctx, 10); p[1].Status != store.IntakeDelivered || p[1].HandoffID != "h-7" {
|
||||
t.Fatalf("pending status: %+v", p)
|
||||
}
|
||||
|
||||
|
||||
@@ -108,4 +108,5 @@ type PendingIntake struct {
|
||||
Danger string `json:"danger"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
HandoffID string `json:"handoff_id,omitempty"`
|
||||
}
|
||||
@@ -124,7 +124,8 @@ func (m *Memory) PendingIntake(_ context.Context, limit int) ([]PendingIntake, e
|
||||
p := PendingIntake{EntryID: e.ID, TenantID: e.TenantID, Reference: e.Reference, Kind: e.Kind, At: e.At,
|
||||
ReceivedAt: r.ReceivedAt, Channel: r.Channel, About: r.About, Danger: r.Danger}
|
||||
if n := len(e.Receipts); n > 0 {
|
||||
p.Status, p.Reason = e.Receipts[n-1].Status, e.Receipts[n-1].Reason
|
||||
last := e.Receipts[n-1]
|
||||
p.Status, p.Reason, p.HandoffID = last.Status, last.Reason, last.HandoffID
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
|
||||
@@ -162,10 +162,10 @@ func (p *Postgres) AddIntakeSupplement(ctx context.Context, tenantID, ref, by st
|
||||
func (p *Postgres) PendingIntake(ctx context.Context, limit int) ([]PendingIntake, error) {
|
||||
rows, err := p.pool.Query(ctx, `
|
||||
SELECT e.id, e.tenant_id::text, e.reference, e.kind, e.at, rp.received_at, rp.channel, rp.about, rp.danger,
|
||||
COALESCE(last.status, ''), COALESCE(last.reason, '')
|
||||
COALESCE(last.status, ''), COALESCE(last.reason, ''), COALESCE(last.handoff_id, '')
|
||||
FROM intake_entries e
|
||||
JOIN intake_reports rp ON rp.tenant_id = e.tenant_id AND rp.reference = e.reference
|
||||
LEFT JOIN LATERAL (SELECT status, reason FROM intake_receipts WHERE entry_id = e.id ORDER BY id DESC LIMIT 1) last ON true
|
||||
LEFT JOIN LATERAL (SELECT status, reason, handoff_id FROM intake_receipts WHERE entry_id = e.id ORDER BY id DESC LIMIT 1) last ON true
|
||||
WHERE NOT EXISTS (SELECT 1 FROM intake_receipts s WHERE s.entry_id = e.id AND s.status IN ('processed', 'refused'))
|
||||
ORDER BY e.id LIMIT $1`, limit)
|
||||
if err != nil {
|
||||
@@ -175,7 +175,7 @@ func (p *Postgres) PendingIntake(ctx context.Context, limit int) ([]PendingIntak
|
||||
out := []PendingIntake{}
|
||||
for rows.Next() {
|
||||
var x PendingIntake
|
||||
if err := rows.Scan(&x.EntryID, &x.TenantID, &x.Reference, &x.Kind, &x.At, &x.ReceivedAt, &x.Channel, &x.About, &x.Danger, &x.Status, &x.Reason); err != nil {
|
||||
if err := rows.Scan(&x.EntryID, &x.TenantID, &x.Reference, &x.Kind, &x.At, &x.ReceivedAt, &x.Channel, &x.About, &x.Danger, &x.Status, &x.Reason, &x.HandoffID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, x)
|
||||
|
||||
@@ -2556,6 +2556,7 @@ components:
|
||||
danger: { type: string }
|
||||
status: { type: string, description: "The newest receipt's status, if any." }
|
||||
reason: { type: string }
|
||||
handoff_id: { type: string, description: "The newest receipt's handoff, if any." }
|
||||
RoleDatasetState:
|
||||
type: object
|
||||
required: [tenant_id, revision, catalogue_version, data, derived, catalogue]
|
||||
|
||||
Reference in new issue
Block a user