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.
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package fileupload
|
|
|
|
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/fileupload/model"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/fileupload/table"
|
|
)
|
|
|
|
func FileInsert(ctx context.Context, txn db.Tx, m model.File) (model.File, error) {
|
|
statement := table.File.INSERT(table.File.MutableColumns).
|
|
MODEL(m).
|
|
RETURNING(table.File.AllColumns)
|
|
return db.ExecuteOneTx[model.File](ctx, txn, statement)
|
|
}
|
|
func FileUpdateCommitting(ctx context.Context, txn db.Tx, org_id int64, file_id int64, committer_id int64) error {
|
|
statement := table.File.UPDATE(
|
|
table.File.Status,
|
|
table.File.Committer,
|
|
).SET(
|
|
table.File.Status.SET(postgres.NewEnumValue(model.Filestatustype_Committing.String())),
|
|
table.File.Committer.SET(postgres.Int(committer_id)),
|
|
).WHERE(postgres.AND(
|
|
table.File.OrganizationID.EQ(postgres.Int(org_id)),
|
|
table.File.ID.EQ(postgres.Int(file_id)),
|
|
))
|
|
return db.ExecuteNoneTx(ctx, txn, statement)
|
|
}
|
|
|
|
/*
|
|
func CommunicationSetStatus(ctx context.Context, txn db.Tx, org_id int64, comm_id int64, status model.Communicationstatus) error {
|
|
statement := table.Communication.UPDATE().
|
|
SET(
|
|
table.Communication.Status.SET(postgres.NewEnumValue(status.String())),
|
|
).
|
|
WHERE(table.Communication.OrganizationID.EQ(postgres.Int(org_id)).AND(
|
|
table.Communication.ID.EQ(postgres.Int(comm_id))))
|
|
return db.ExecuteNoneTx(ctx, txn, statement)
|
|
}
|
|
|
|
func EmailLogFromID(ctx context.Context, id int64) (model.EmailLog, error) {
|
|
statement := table.EmailLog.SELECT(
|
|
table.EmailLog.AllColumns,
|
|
).FROM(table.EmailLog).
|
|
WHERE(table.EmailLog.ID.EQ(postgres.Int(id)))
|
|
return db.ExecuteOne[model.EmailLog](ctx, statement)
|
|
}
|
|
func EmailLogsFromAddress(ctx context.Context, address string) ([]model.EmailLog, error) {
|
|
statement := table.EmailLog.SELECT(
|
|
table.EmailLog.AllColumns,
|
|
).FROM(table.EmailLog).
|
|
WHERE(table.EmailLog.Source.EQ(postgres.String(address)).OR(
|
|
table.EmailLog.Destination.EQ(postgres.String(address))))
|
|
return db.ExecuteMany[model.EmailLog](ctx, statement)
|
|
}
|
|
*/
|