Following #1105 (comment), I think this is worth a separate issue.
As I already described in #1105, there is a theoretically possible situation when actually running and healthy job is marked as discarded. And while it is marked as discarded worker might still continue executing it because it did not receive any notification about job being discarded. It creates a situation which might violate unique_key invariant, as happened in the linked issue — discarded job goroutine is actually running and new job can be potentially scheduled, not violating unique key constraint as from db point of view this is correct
|
CREATE UNIQUE INDEX IF NOT EXISTS river_job_unique_idx ON /* TEMPLATE: schema */river_job (unique_key) |
|
WHERE unique_key IS NOT NULL |
|
AND unique_states IS NOT NULL |
|
AND /* TEMPLATE: schema */river_job_state_in_bitmask(unique_states, state); |
I guess it either could be done through pg_notify or polling job row every few seconds, and the second one is not great for db. I don't know what are other good options, so creating this issue to discuss
Following #1105 (comment), I think this is worth a separate issue.
As I already described in #1105, there is a theoretically possible situation when actually running and healthy job is marked as
discarded. And while it is marked asdiscardedworker might still continue executing it because it did not receive any notification about job being discarded. It creates a situation which might violateunique_keyinvariant, as happened in the linked issue —discardedjob goroutine is actually running and new job can be potentially scheduled, not violating unique key constraint as from db point of view this is correctriver/riverdriver/riverpgxv5/migration/main/006_bulk_unique.up.sql
Lines 30 to 33 in a8d8127
I guess it either could be done through
pg_notifyor polling job row every few seconds, and the second one is not great for db. I don't know what are other good options, so creating this issue to discuss