Goal
Ensure resilient database batch updates when message failures occur.
Problem
In src/consumer.ts, when processing a batch of events inside a PostgreSQL transaction (BEGIN ... COMMIT), if a single metric write fails due to constraint violations or database issues, PostgreSQL marks the active transaction as aborted. The loop keeps trying to issue queries on the aborted client, the final COMMIT fails, and the worker loops indefinitely re-consuming the exact same batch.
Task
- Resolve the aborted transaction block issue in the consumer batch loop.
- You can rewrite the writes as a single bulk
INSERT query (using dynamic values) with ON CONFLICT DO NOTHING to avoid individual line failures.
- Alternatively, utilize SQL
SAVEPOINT sub-transactions to isolate individual insert errors.
Goal
Ensure resilient database batch updates when message failures occur.
Problem
In
src/consumer.ts, when processing a batch of events inside a PostgreSQL transaction (BEGIN...COMMIT), if a single metric write fails due to constraint violations or database issues, PostgreSQL marks the active transaction as aborted. The loop keeps trying to issue queries on the aborted client, the finalCOMMITfails, and the worker loops indefinitely re-consuming the exact same batch.Task
INSERTquery (using dynamic values) withON CONFLICT DO NOTHINGto avoid individual line failures.SAVEPOINTsub-transactions to isolate individual insert errors.