Skip to content
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 a rollback method on resources to handle manually defining a transaction #137

Open
Startouf opened this issue Sep 2, 2018 · 2 comments

Comments

@Startouf
Copy link

Startouf commented Sep 2, 2018

When dealing with transactionless operations (MongoDB, ElasticSearch, etc.) it is not possible to redefine the transaction, yet it would make sense to have a rollback method that would yield the model that was created or updated (ie the return of the create/update method.

Based on that, it would become possible to either destroy or just rollback the changes manually (ActiveModel has a nice previous_changes builtin method)

class FooResource

  def create(attributes)
    Foo.create(attributes)
  end

  def rollback(resource:, method:)
    if method == :create
      resource.destroy
    else
      resource.update_attributes(resource.previous_changes)
    end 
  end

The idea being that the rollback method would be fired automatically if there is for example a failure while persisting the related resources / sideposting

@Startouf
Copy link
Author

Startouf commented Sep 2, 2018

Hum... handled by #72 (review) ?

@richmolj
Copy link
Contributor

richmolj commented Sep 2, 2018

I would definitely like this functionality, and I think the linked comment by @wadetandy is the way to go. I'm currently working on transitioning this to graphiti (beta next week) if you'd like to submit a PR there (otherwise will be a little while until I can get to it). Specs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants