Skip to content

Instantly share code, notes, and snippets.

@andrewsmedina
Created August 18, 2014 14:55
Show Gist options
  • Save andrewsmedina/796d3f22eba3e00ff03e to your computer and use it in GitHub Desktop.
Save andrewsmedina/796d3f22eba3e00ff03e to your computer and use it in GitHub Desktop.
class Action(object):
def backward(self):
raise NotImplemented
def forward(self):
raise NotImplemented
class Pipeline(object):
def __init__(self, actions):
self.actions = actions
def execute(self):
try:
for action in self.actions:
action.forward()
except:
self.rollback(action)
def rollback(self, action):
index = self.actions.index(action) - 1
while index > 0:
action = self.actions[index]
action.backward()
index = index - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment