Skip to content

Commit

Permalink
fix(pegboard): handle conflicts for client events gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Dec 19, 2024
1 parent 5a53b0b commit c152a11
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/services/pegboard/src/workflows/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,24 @@ async fn insert_events(ctx: &ActivityCtx, input: &InsertEventsInput) -> GlobalRe
return Ok(());
};

// TODO(RVT-4450): `last_event_idx < $2` and `ON CONFLICT DO NOTHING` is a workaround
sql_execute!(
[ctx]
"
WITH
update_last_event_idx AS (
UPDATE db_pegboard.clients
SET last_event_idx = $2
WHERE client_id = $1
WHERE
client_id = $1 AND
last_event_idx < $2
RETURNING 1
),
insert_events AS (
INSERT INTO db_pegboard.client_events (client_id, index, payload, ack_ts)
SELECT $1, index, payload, $5
FROM UNNEST($3, $4) AS e(index, payload)
ON CONFLICT DO NOTHING
RETURNING 1
)
SELECT 1
Expand Down

0 comments on commit c152a11

Please sign in to comment.