コード例 #1
0
ファイル: lifecycle.py プロジェクト: gueux/growbox420
def get_lifecycle(item):
    lifecycle = []
    connection = rdb_connector()
    logger.info("Loading lifecycle for `%s` from storage", item)
    cursor = RDB.db(DB_NAME).table(item).order_by('order').run(connection)
    for phase in cursor:
        lifecycle.append(phase)
    logger.debug("Loaded lifecycle: %s", lifecycle)
    return lifecycle
コード例 #2
0
ファイル: load.py プロジェクト: gueux/growbox420
def import_db_from_yaml():
    data_tree = []
    for index, tree in enumerate(os.walk(DATA_PATH)):
        if index > 0:
            data_tree.append(tree)

    for data in data_tree:

        database = data[0].split('/')[-1]

        connection = rdb_connector()
        try:
            RDB.db_create(database).run(connection)
            logger.info("Database `%s` setup completed", database)
        except RqlRuntimeError:
            logger.error("Database `%s` already exists", database)
        except RqlDriverError as e:
            logger.error(e)
            exit()
        finally:
            connection.close()

        tables = data[2]

        for table in tables:
            table_name = os.path.splitext(table)[0]
            table_data = read_yaml(DATA_PATH + '/' + database + '/' + table)
            connection = rdb_connector()
            try:
                RDB.db(database).table_create(table_name).run(connection)
                RDB.db(database).table(table_name).insert(table_data).run(
                    connection)
                logger.info("Table `%s` setup in database `%s` completed",
                            table_name, database)
            except RqlRuntimeError:
                logger.error("Table `%s` in database `%s` already exists",
                             table_name, database)
            except RqlDriverError as e:
                logger.error(e)
                exit()
            finally:
                connection.close()
コード例 #3
0
ファイル: start.py プロジェクト: gueux/growbox420
def collector():
    while True:
        logger.info("Calculate current phase and time of the day...")
        config.CURRENT_PHASE = current_phase(LIFECYCLE, startup_date_time)
        logger.info("Collecting current metrics...")
        all_metrics()
        logger.info("Metrics Collected. Sleep for %s sec...",
                    config.READ_EVERY_SEC)
        time.sleep(config.READ_EVERY_SEC)
コード例 #4
0
ファイル: start.py プロジェクト: gueux/growbox420
def controller():
    logger.info("Starting Flask HTTP server...")
    app.run(host=config.FLASK_HOST,
            port=config.FLASK_PORT,
            debug=True,
            use_reloader=False)
コード例 #5
0
ファイル: start.py プロジェクト: gueux/growbox420
def collector():
    while True:
        logger.info("Calculate current phase and time of the day...")
        config.CURRENT_PHASE = current_phase(LIFECYCLE, startup_date_time)
        logger.info("Collecting current metrics...")
        all_metrics()
        logger.info("Metrics Collected. Sleep for %s sec...",
                    config.READ_EVERY_SEC)
        time.sleep(config.READ_EVERY_SEC)


if __name__ == "__main__":

    # Moment when the growcycle was started

    startup_date_time = datetime.datetime.now()

    logger.info("====================================")
    logger.info("Startup Date/Time: %s",
                startup_date_time.strftime("%y-%m-%d %H:%M:%S"))
    logger.info("====================================")
    logger.info("Controller starting in separate thread...")
    logger.info("====================================")

    threading.Thread(target=controller).start()

    logger.info("====================================")
    logger.info("Collector starting in separate thread...")
    logger.info("====================================")

    threading.Thread(target=collector).start()