dry-rb / dry-transaction

Business transaction DSL
http://dry-rb.org/gems/dry-transaction
MIT License
468 stars 55 forks source link

Allow running a transaction from a particular step #113

Closed timriley closed 5 years ago

nicolas-besnard commented 5 years ago

Hey @timriley!

Do you have more info about what you want to achieve?

timriley commented 5 years ago

Hi @nicolas-besnard, thanks for expressing your interest here.

Apart from the obvious description of the feature ("Allow running a transaction from a particular step"), the idea here is to allow a transaction to be "re-entered" midway through so various custom step adapters can become more helpful.

Here's an example: in the apps I make with dry-transaction, I typically add an enqueue step adapter that enqueues the corresponding step operation to run as a background job. This is great and helpful, but the problem is that I can't have any subsequent steps depend on the outcome of the backgrounded operation (because at that point the transaction is no longer around).

What would be neat is for my enqueue adapter to know which step it is in a transaction, and then when the operation running in the background completes, then it would enqueue another job that re-starts the transaction from the subsequent step.

Does that make sense? Most of the implementation of that kind of behaviour would fall outside of the the scope of this issue, but to make it possible, we need to allow some kind of API like my_transaction.from_step(:foo) to return a new transaction that when called, would only start from the :foo step.