diff options
| author | Dan Krause <dan.krause@rackspace.com> | 2015-03-03 10:57:09 -0600 |
|---|---|---|
| committer | Dan Krause <dan.krause@rackspace.com> | 2015-03-09 15:38:56 -0500 |
| commit | 3e8eb915b55dfd6577a9cdb313afc71fd6d44b1a (patch) | |
| tree | 6dcb88193facaef0f81db831dd69604064b77d2f /taskflow/persistence/backends/impl_sqlalchemy.py | |
| parent | 00ab6289ab834be3e938c1aed8385361159d7f63 (diff) | |
| download | taskflow-3e8eb915b55dfd6577a9cdb313afc71fd6d44b1a.tar.gz | |
Persistence backend refactor
Factors lots of duplicate code out of persistence backends
Adds get_flows_for_book to all backends
Change-Id: I0434bd4931cd9274876f9e9c92909531f244bcac
Diffstat (limited to 'taskflow/persistence/backends/impl_sqlalchemy.py')
| -rw-r--r-- | taskflow/persistence/backends/impl_sqlalchemy.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/taskflow/persistence/backends/impl_sqlalchemy.py b/taskflow/persistence/backends/impl_sqlalchemy.py index a49d249..4368b78 100644 --- a/taskflow/persistence/backends/impl_sqlalchemy.py +++ b/taskflow/persistence/backends/impl_sqlalchemy.py @@ -202,25 +202,25 @@ class Alchemist(object): atom_cls = logbook.atom_detail_class(row.pop('atom_type')) return atom_cls.from_dict(row) - def _atom_query_iter(self, conn, parent_uuid): + def atom_query_iter(self, conn, parent_uuid): q = (sql.select([self._tables.atomdetails]). where(self._tables.atomdetails.c.parent_uuid == parent_uuid)) for row in conn.execute(q): yield self.convert_atom_detail(row) - def _flow_query_iter(self, conn, parent_uuid): + def flow_query_iter(self, conn, parent_uuid): q = (sql.select([self._tables.flowdetails]). where(self._tables.flowdetails.c.parent_uuid == parent_uuid)) for row in conn.execute(q): yield self.convert_flow_detail(row) def populate_book(self, conn, book): - for fd in self._flow_query_iter(conn, book.uuid): + for fd in self.flow_query_iter(conn, book.uuid): book.add(fd) self.populate_flow_detail(conn, fd) def populate_flow_detail(self, conn, fd): - for ad in self._atom_query_iter(conn, fd.uuid): + for ad in self.atom_query_iter(conn, fd.uuid): fd.add(ad) @@ -558,6 +558,19 @@ class Connection(base.Connection): for book in gathered: yield book + def get_flows_for_book(self, book_uuid): + gathered = [] + try: + with contextlib.closing(self._engine.connect()) as conn: + for row in self._converter.flow_query_iter(conn, book_uuid): + flow_details = self._converter.populate_flow_detail(conn, + row) + gathered.append(flow_details) + except sa_exc.DBAPIError as e: + raise exc.StorageFailure("Failed getting flow details", e) + for flow_details in gathered: + yield flow_details + def get_flow_details(self, fd_uuid): try: flowdetails = self._tables.flowdetails |
