-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add transactional enqueuing #53
Comments
Hi @nathankawalec! There is |
Sorry for the late response. Upon further review, I think all that is required is something like: Only issue I can think of is pgxpool transaction doesn't implement Close or Ping methods, which would require end user to wrap the transaction object in order to implement those methods (with no op) I believe Close method called on rows in SendBatchWithDelay, ReadBatch, ArchiveBatch, and DeleteBatch can be safely called in a transaction with more work to be done, but I may be mistaken. I think ideally it would be possible to use each method inside a transaction. |
Oops, didn't mean to close. |
My 2 cents here: with commit 1e953ef it became clear that the transaction is fully supported by pgmq. |
I finally got around to implementing this in #63. I dropped the
In particular, Example usage:
WDYT? |
If I understand correctly, the DB connection object will be maintained outside of the pgmq-go library and only passed on as parameter for each exposed method, right ? Is this correct ? |
Correct. I think it makes sense because you may be doing many other things with the connection. The advantage of using a queue in Postgres. Of course we could provide convenience functions like CreatePgxPool, etc. if those are valuable. |
There will be use cases where the transactions are not required / needed. Since the library requires anyways to work with a DB compliant connection, probably it would be easier to accept a pointer to the active DB object at the initialization and use that reference forward - thus avoiding to pass every time the DB object as parameter. What do you think ? |
Oh yeah, definitely. I aimed for a general API that would support all/most use cases. So, if you don't need transactions and just want to use PGMQ, then the simplest way would be
It is a bit annoying to pass the DB object in every case, but it was the least objectionable solution that I could think of and facilitates interweaving with other DB operations and working with transactions. I thought about accepting the pointer to the active DB object and defining methods on that, but then how would one work with transactions? I thought of adding extra methods that work on transactions, or perhaps adding an extra argument to take an optional transaction and use the transaction if supplied, but neither of these were that nice to me. |
If you would accept the pointer to the DB object, the transaction aware methods could :
I would see something like:
Both methods could have a boolean flag to ensure the extensions is present / created
The API looks more consistent like this, in my opinion ... |
It would be very beneficial to be able to queue messages in a transaction, similar to what riverqueue offers (https://pkg.go.dev/github.com/riverqueue/river#Client.InsertTx), this would completely mitigate errors that could arise if data is added to a db and a crash occurs before the message could be queued, or vice versa.
This can be done either by returning a pointer to a tx or by accepting a tx as an input parameter when queuing a message. If this is a feature you could add it would be very appreciated :)
The text was updated successfully, but these errors were encountered: