Project

transactor

0.0
No commit activity in last 3 years
No release in over 3 years
Transactional actors for easy rollbacks
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Transactor

Build Status Coverage Status Code Climate Gem Version Dependency Status

Transactional actors for easy rollbacks of performances.

If one of these operations fails, execution is halted and all previous operations are rolled back using their defined rollback functionality:

Transactor.transaction do
  perform CacheInRedis, key, value
  perform UpdateActiveRecord, my_attr: value
  MyModel.update!(my_attr: value) # don't even need to use transactor when using active_record
  perform SendChargeToStripe.new(amount)
  perform :email_customer, user, amount
end

Transactor.transaction do
  cache_in_redis key, value
  update_active_record my_attr: value
  MyModel.update!(my_attr: value) # don't even need to use transactor when using active_record
  send_charge_to_stripe amount
  email_customer user, amount
end

Transactor.transaction cache_in_redis: [key, value], update_active_record: {my_attr: value}, send_charge_to_stripe: amount, email_customer: [user, amount]

Transactor.transaction do
  improvise(*args) do
    # do something here
  end.rollback do
    # roll it back if something fails after this block
  end

  improvise.rollback do
    # don't actually perform any additionalimprov operations,
    # but DO perform some special one-off rollback logic if
    # stuff below fails
  end

  # another transactor could go here or simply anything
  # that might raise an exception
end


class CacheInRedis < Transactor::Actor
  def perform
    # put your key/value into redis

    # OR save the old value to an instance var and
    # update with the new value
  end

  def rollback
    # delete your key/value

    # OR restore the old value from an instance var
  end
end

class UpdateActiveRecord < Transactor::Actor
  def perform
    MyModel.update(my_attr: @my_attr)
  end

  def rollback
    # automatic, optional if there is extra work to do, all
    # Transactor transactions are also ActiveRecord transactions
  end
end

class SendChargeToStripe < Transactor::Actor
  def perform
    # send a charge to Stripe
  end

  def rollback
    # send a cancellation for the charge
  end
end

class EmailCustomer < Transactor::Actor
  def perform
    # send an email to the customer
  end

  def rollback
    # maybe do nothing?
    # maybe send an email that there was a problem
  end
end

TODO

  • documentation