Skip to content

Instantly share code, notes, and snippets.

@harlowja
Created July 2, 2014 20:42
Show Gist options
  • Save harlowja/d8d02f4be0f3f03cb384 to your computer and use it in GitHub Desktop.
Save harlowja/d8d02f4be0f3f03cb384 to your computer and use it in GitHub Desktop.
Storage idea
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class BaseStorage(object):
def ensure_atom(self, atom):
def set_atom_state(self, atom_name, state):
def set_atom_intention(self, atom_name, intention):
def set_flow_state(self, flow_uuid, state):
def update_atom_metadata(self, atom_name, update_with):
def save_progress(self, atom_name, progress, details=None):
def save(self, atom_name, data, state=states.SUCCESS):
def get(self, atom_name): # read-only
def get_flow_state(self, flow_uuid):
def get_atom_intention(self):
# Maybe we should stop returning an intention here and just return
# the atom detail using get()
def fetch(self, name):
def fetch_all(self):
def fetch_mapped_args(self, args_mapping, atom_name=None):
# This one we implement; not leave abstract
def has_failures(self):
def get_failures(self)
def inject_atom_symbols(self, atom_name, pairs):
def inject(self, pairs, transient=False):
# Ones that I'd rather not provide, to specific to individual types, any
# ideas where these should go?
def get_retry_history()
@six.add_metaclass(abc.ABCMeta)
class StorageBackend(object):
def makeStorageFor(self, flows):
# Flows is allowed to be a list of flows to get a storage unit for,
# or it can also be a dictionary of flows => uuids (this allows the
# backend to fetch a storage unit using existing uuids for existing?
# flows).
#
# We could just say that it always be a dictionary and when the
# value is None (or empty..) the backend is free to populate its
# internal space for that flow and not have to lookup an existing one...
#
# In the current model this would just be 1 flow (but doesn't limit
# itself to being just 1 flow).
class SuperSQLAlchemyBackend(StorageBackend):
# The main method that engines use/interact with, backends can do whatever
# they want to provide the impl.
def makeStorageFor(self, flows):
# Useful other backend apis that are backend specific and do not make
# sense in all backends, but do make sense where available.
def getAllStoppedAtoms(self):
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment