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.
27 lines
835 B
Go
27 lines
835 B
Go
package public
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Gleipnir-Technology/jet/postgres"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/model"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/table"
|
|
)
|
|
|
|
func JobInsert(ctx context.Context, txn db.Ex, m model.Job) (model.Job, error) {
|
|
statement := table.Job.INSERT(table.Job.MutableColumns).
|
|
MODEL(m).
|
|
RETURNING(table.Job.AllColumns)
|
|
return db.ExecuteOneTx[model.Job](ctx, txn, statement)
|
|
}
|
|
func JobNotify(ctx context.Context, txn db.Ex, channel string, payload string) error {
|
|
statement := postgres.RawStatement(
|
|
"SELECT pg_notify(#channel, #payload)",
|
|
postgres.RawArgs{
|
|
"#channel": channel,
|
|
"#payload": payload,
|
|
},
|
|
)
|
|
return db.ExecuteNoneTx(ctx, txn, statement)
|
|
}
|