Why there is no `Ash.Changeset.around_transaction`?
I was wondering why there is no
I know that there is a
Just to give a more concrete example.
I'm planning to port this into a Ash change:
The idea in this function is that I will first use
I then run the
If I just wanted to create the transaction row in the DB, I would be able to create two changes, one with
around_transaction function in Ash.Changeset. We already have a around_action option, but that one runs inside a transaction, meaning that I can't use it if I wan't to add something to the DB regardless if the action itself fails or not.I know that there is a
before_transaction and after_transaction, but depending on what I'm doing this would not work.Just to give a more concrete example.
I'm planning to port this into a Ash change:
The idea in this function is that I will first use
Mutex to make sure that I always have only one code path reaching this code block at a time, after it, I create a transaction, which basically means that I have a transaction table and I store a row there for that user and type.I then run the
apply_function, if that function doesn't return an error, it will call the delete_transaction! function that will remove the transaction and return the response, otherwise, it will just crash leaving the added transaction in the DB, this means that next time this code is called, it will fail to create a transaction and it will run the update_function instead.If I just wanted to create the transaction row in the DB, I would be able to create two changes, one with
after_transaction(to create the row) and one with before_transaction (to delete it), but that doesn't work with the Mutex call, for the mutex I need something like around_action but for transactions.