fix(eda): the undispatched-capture batch lists only captures an enabled binding still owes

Issue: archie-core-kfjz1
This commit is contained in:
sam committed 2026-10-13 16:21:21 +11:00
1 parent 796c7a711b
commit 7435b6efe5
10 files changed
+49 -37

No files matched your search

+5 -5
View File
@@ -166,16 +166,16 @@ func (s *EDA) ListCaptures(ctx context.Context, limit int) ([]storecontract.Capt
}
// ListUndispatchedCaptures returns the oldest dispatchable, identified
// captures for the given sources that some armed binding for their event type
// has not dispatched yet. An unidentified capture is never returned, so it
// captures that one of the given armed bindings, for their event type, has not
// dispatched yet. An unidentified capture is never returned, so it
// never dispatches.
func (s *EDA) ListUndispatchedCaptures(ctx context.Context, sources []string, limit int) ([]storecontract.CapturedEvent, error) {
if len(sources) == 0 || limit <= 0 {
func (s *EDA) ListUndispatchedCaptures(ctx context.Context, bindings []string, limit int) ([]storecontract.CapturedEvent, error) {
if len(bindings) == 0 || limit <= 0 {
return nil, nil
}
rows, err := s.q.ListUndispatchedCaptures(ctx, postgresdb.ListUndispatchedCapturesParams{
OrgID: string(org.OrgFromContext(ctx)),
Sources: sources,
Bindings: bindings,
EntryLimit: int32(limit),
})
if err != nil {
@@ -1024,12 +1024,13 @@ func (q *Queries) ListSources(ctx context.Context, scopeOrg pgtype.Text) ([]Sour
const listUndispatchedCaptures = `-- name: ListUndispatchedCaptures :many
SELECT c.id, c.source, c.remote_addr, c.content_type, c.headers, c.body, c.authenticated, c.received_at, c.unsigned, c.event_type, c.org_id, c.workspace_id, c.delivery
FROM captures c
WHERE c.org_id = $1 AND c.source = ANY($2::text[])
WHERE c.org_id = $1
AND c.event_type <> ''
AND (c.authenticated OR c.unsigned)
AND EXISTS (
SELECT 1 FROM bindings b JOIN mappings m ON m.id = b.mapping
WHERE b.org_id = c.org_id AND b.source = c.source AND b.status = 'armed' AND m.event_type = c.event_type
AND b.id = ANY($2::text[])
AND NOT EXISTS (SELECT 1 FROM binding_dispatches d WHERE d.binding = b.id AND d.delivery = c.delivery)
)
ORDER BY c.received_at, c.id
@@ -1038,15 +1039,16 @@ LIMIT $3
type ListUndispatchedCapturesParams struct {
OrgID string
Sources []string
Bindings []string
EntryLimit int32
}
// Oldest first, so sustained intake cannot starve accepted work. Only
// dispatchable captures (signed, or from an approved unsigned source) are
// listed: no binding ever matches the rest, so they would hold the batch.
// dispatchable captures (signed, or from an approved unsigned source) that one
// of the named bindings still owes a dispatch are listed: no other capture
// would ever be dispatched, so it would hold the batch.
func (q *Queries) ListUndispatchedCaptures(ctx context.Context, arg ListUndispatchedCapturesParams) ([]Capture, error) {
rows, err := q.db.Query(ctx, listUndispatchedCaptures, arg.OrgID, arg.Sources, arg.EntryLimit)
rows, err := q.db.Query(ctx, listUndispatchedCaptures, arg.OrgID, arg.Bindings, arg.EntryLimit)
if err != nil {
return nil, err
}
@@ -15,16 +15,18 @@ LIMIT $1;
-- name: ListUndispatchedCaptures :many
-- Oldest first, so sustained intake cannot starve accepted work. Only
-- dispatchable captures (signed, or from an approved unsigned source) are
-- listed: no binding ever matches the rest, so they would hold the batch.
-- dispatchable captures (signed, or from an approved unsigned source) that one
-- of the named bindings still owes a dispatch are listed: no other capture
-- would ever be dispatched, so it would hold the batch.
SELECT c.id, c.source, c.remote_addr, c.content_type, c.headers, c.body, c.authenticated, c.received_at, c.unsigned, c.event_type, c.org_id, c.workspace_id, c.delivery
FROM captures c
WHERE c.org_id = @org_id AND c.source = ANY(@sources::text[])
WHERE c.org_id = @org_id
AND c.event_type <> ''
AND (c.authenticated OR c.unsigned)
AND EXISTS (
SELECT 1 FROM bindings b JOIN mappings m ON m.id = b.mapping
WHERE b.org_id = c.org_id AND b.source = c.source AND b.status = 'armed' AND m.event_type = c.event_type
AND b.id = ANY(@bindings::text[])
AND NOT EXISTS (SELECT 1 FROM binding_dispatches d WHERE d.binding = b.id AND d.delivery = c.delivery)
)
ORDER BY c.received_at, c.id