This is kind of a wild one. Turns out that the triggers I was using actually fire before the transaction is closed and I was primarily getting lucky that the job was present on the other side of the connection rather than having things built correctly. I've fixed this by removing the trigger entirely and instead manually triggering as part of the transaction. This makes the NOTIFY call happen as soon as the transaction closes, just at the cost of making my application be in charge of ensuring the NOTIFY gets called. Seems like a win. Part of doing this is porting the existing job creation code over to use Jet. It's something I want to do anyway, so it's a win all around.
19 lines
426 B
PL/PgSQL
19 lines
426 B
PL/PgSQL
-- +goose Up
|
|
DROP TRIGGER job_insert_trigger ON job;
|
|
DROP FUNCTION notify_new_job();
|
|
|
|
-- +goose Down
|
|
-- +goose StatementBegin
|
|
CREATE OR REPLACE FUNCTION notify_new_job()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
PERFORM pg_notify('new_job', NEW.id::text);
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
-- +goose StatementEnd
|
|
|
|
CREATE TRIGGER job_insert_trigger
|
|
AFTER INSERT ON job
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION notify_new_job();
|