예제 #1
0
def check_and_run():
    backend = impl_sqlalchemy.SQLAlchemyBackend(CONF)
    if sql_exec.flowdetails is None:
        return

    if sql_exec.flowdetails[5] != u'SUCCESS':
        book_id = sql_exec.flowdetails[2]
        flow_id = sql_exec.flowdetails[6]

    else:
        return

    flow_detail = None

    if all([book_id, flow_id]):
        try:
            with contextlib.closing(backend.get_connection()) as conn:
                lb = conn.get_logbook(book_id)
                flow_detail = lb.find(flow_id)

        except exc.NotFound:
            pass

    flow_engine = taskflow.engines.load_from_detail(flow_detail,
                                                    backend=backend,
                                                    engine='serial')

    with flow_utils.DynamicLogListener(flow_engine, logger=LOG):
        LOG.info("Starting to run previously unfinished task flow")
        flow_engine.run()
        LOG.info("The previously partially completed flow is finished.")
def main():
    backend = impl_sqlalchemy.SQLAlchemyBackend(CONN_CONF)
    with contextlib.closing(backend) as backend:
        # Make the schema exist...
        with contextlib.closing(backend.get_connection()) as conn:
            conn.upgrade()
        # Now make a prettier version of that schema...
        tables = backend.engine.execute(TABLE_QUERY)
        table_names = [r[0] for r in tables]
        for i, table_name in enumerate(table_names):
            pretty_name = NAME_MAPPING.get(table_name, table_name)
            print("*" + pretty_name + "*")
            # http://www.sqlite.org/faq.html#q24
            table_name = table_name.replace("\"", "\"\"")
            rows = []
            for r in backend.engine.execute(SCHEMA_QUERY % table_name):
                # Cut out the numbers from things like VARCHAR(12) since
                # this is not very useful to show users who just want to
                # see the basic schema...
                row_type = re.sub(r"\(.*?\)", "", r['type']).strip()
                if not row_type:
                    raise ValueError("Row %s of table '%s' was empty after"
                                     " cleaning" % (r['cid'], table_name))
                rows.append([r['name'], row_type, to_bool_string(r['pk'])])
            contents = tabulate.tabulate(
                rows, headers=['Name', 'Type', 'Primary Key'],
                tablefmt="rst")
            print("\n%s" % contents.strip())
            if i + 1 != len(table_names):
                print("")
 def setUp(self):
     super(BackendPersistenceTestMixin, self).setUp()
     self.backend = None
     try:
         self.db_uri = self._init_db()
         self.db_conf = {'connection': self.db_uri}
         # Since we are using random database names, we need to make sure
         # and remove our random database when we are done testing.
         self.addCleanup(self._remove_db)
     except Exception as e:
         self.skipTest("Failed to create temporary database;"
                       " testing being skipped due to: %s" % (e))
     else:
         self.backend = impl_sqlalchemy.SQLAlchemyBackend(self.db_conf)
         self.addCleanup(self.backend.close)
         with contextlib.closing(self._get_connection()) as conn:
             conn.upgrade()
예제 #4
0
 def setUp(self):
     super(BackendPersistenceTestMixin, self).setUp()
     self.backend = None
     self.big_lock.acquire()
     self.addCleanup(self.big_lock.release)
     try:
         conf = {
             'connection': self._reset_database(),
         }
     except Exception as e:
         self.skipTest("Failed to reset your database;"
                       " testing being skipped due to: %s" % (e))
     try:
         self.backend = impl_sqlalchemy.SQLAlchemyBackend(conf)
         self.addCleanup(self.backend.close)
         with contextlib.closing(self._get_connection()) as conn:
             conn.upgrade()
     except Exception as e:
         self.skipTest("Failed to setup your database;"
                       " testing being skipped due to: %s" % (e))
예제 #5
0
파일: manager.py 프로젝트: hebin10/rock
def run_flow(flow_name, store_spec, tasks):
    """Constructs and run a task flow.
    """

    backend = impl_sqlalchemy.SQLAlchemyBackend(CONF)

    book = models.LogBook(flow_name)

    with contextlib.closing(backend.get_connection()) as conn:
        conn.save_logbook(book)
    # Now load (but do not run) the flow using the provided initial data.
    flow_engine = taskflow.engines.load_from_factory(create_flow,
                                                     factory_args=(flow_name,
                                                                   tasks),
                                                     store=store_spec,
                                                     backend=backend,
                                                     book=None,
                                                     engine='serial')

    with flow_utils.DynamicLogListener(flow_engine, logger=LOG):
        flow_engine.run()
        LOG.info("taskflow execute is successfully.")
 def _get_connection(self):
     conf = {
         'connection': self.db_uri,
     }
     return impl_sqlalchemy.SQLAlchemyBackend(conf).get_connection()