-
Notifications
You must be signed in to change notification settings - Fork 33
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
Micro::Cases.flow(db_transaction: true) #44
Comments
why not just |
@marlosirapuan I'm not sure about the method name yet. But this mode could be enabled using a kwarg. e.g: Micro::Cases.flow(transaction: true, [
CreateUser,
CeateUserProfile
])
# --
class MyCase < Micro::Case
flow(transaction: true, [
CreateUser,
CeateUserProfile
]) What do you think? cc: @MatheusRich |
To me An alternative: MyFlowWrappedInATransaction = Micro::Cases.flow(db_transaction: true, [
CreateUser,
CeateUserProfile
]) |
@MatheusRich I liked the usage of |
@serradura how about? MyFlow = Micro::Cases.flow(transaction: :db, [])
# or
MyFlow = Micro::Cases.flow(transaction: Micro::Cases::DB_TRANSACTION, [])
# or
MyFlow = Micro::Cases.flow(transaction: MyCustomImplementation, []) |
@mrbongiolo I can think of different types of transactions. But I would like to start solving this first one: DB transactions. As you proposed, I believe that if a new kind of transaction appears, we could make |
@serradura I totally agree with @mrbongiolo suggestion of I've worked on applications that had more than one ActiveRecord or Sequel db connections. The transaction itself would not even need to be part of the project. And just provide mechanisms to group the a list of cases in a single transaction. And good examples in the documentation. I don't think someone is using two ORM like this in same application. But a generic API would make that possible: class SequelTransaction < Micro::Cases::Transaction
def call!
result = nil
SequelDB.transaction do
result = yield
raise Sequel::Rollback if result.failure?
end
result
end
end
class ActiveRecordTransaction < Micro::Cases::Transaction
def call!
result = nil
ApplicationRecord.transaction do
result = yield
raise ActiveRecord::Rollback if result.failure?
end
result
end
end
SignInFlow = Micro::Cases.flow(transaction: ActiveRecordTransaction, [CreateUser, CreateProfile])
SubscribeFlow = Micro::Cases.flow(transaction: SequelTransaction, [CreateOrder, CreateSubscription]) Ignore the syntax itself of this example. I'm talking the idea of a generic transaction. |
I was thinking exactly in that way, so the gem could have its own AR db transaction implementation (just for easy of use), but it could receive any object that respects the u-case transaction API.
|
Hello @serradura . Do we have any plans to add this feature still? I was looking exactly for support to db transactions in a flow. |
Wraps a
Micro::Cases::Flow
inside of anActiveRecord::Transactions
and if an exception happening or any step returns a failure, this flow will be halted because anActiveRecord::Rollback
will be raised.Definition of done:
kind
andu-attributes
, this gem never will require any external dependency by default.Thanks, @marlosirapuan, @josuetex, @marcosgz, @MatheusRich, @mrbongiolo for helping me to elaborate on this idea. 🚀
The text was updated successfully, but these errors were encountered: