Esempio n. 1
0
def schedule():
    global running
    global _outstanding_data_migrations

    _outstanding_data_migrations = [
        m for m in DataMigration.all() if not m.is_finished
    ]
    if _outstanding_data_migrations:
        log.debug('Incomplete data migrations will be run: %s',
                  ', '.join(m.name for m in _outstanding_data_migrations))

    interface.start(config)

    if config.get('carbon.address'):
        log.debug('starting metrics thread')
        metrics_thread = threading.Thread(target=metrics_loop, name='metrics')
        metrics_thread.daemon = True
        metrics_thread.start()

    beakerd_threads = set(["main_recipes"])

    log.debug("starting main recipes thread")
    main_recipes_thread = threading.Thread(target=main_recipes_loop,
                                           name="main_recipes")
    main_recipes_thread.daemon = True
    main_recipes_thread.start()

    try:
        while True:
            time.sleep(20)
            running_threads = set([t.name for t in threading.enumerate()])
            if not running_threads.issuperset(beakerd_threads):
                log.critical("a thread has died, shutting down")
                rc = 1
                running = False
                event.set()
                break
            event.set()
            event.clear()
    except (SystemExit, KeyboardInterrupt):
        log.info("shutting down")
        running = False
        event.set()
        rc = 0

    if _threadpool_executor:
        _threadpool_executor.shutdown()
    interface.stop()
    main_recipes_thread.join(10)

    sys.exit(rc)
Esempio n. 2
0
def schedule():
    global running
    global _outstanding_data_migrations

    _outstanding_data_migrations = [m for m in DataMigration.all() if not m.is_finished]
    if _outstanding_data_migrations:
        log.debug('Incomplete data migrations will be run: %s',
                ', '.join(m.name for m in _outstanding_data_migrations))

    interface.start(config)

    if config.get('carbon.address'):
        log.debug('starting metrics thread')
        metrics_thread = threading.Thread(target=metrics_loop, name='metrics')
        metrics_thread.daemon = True
        metrics_thread.start()

    beakerd_threads = set(["main_recipes"])

    log.debug("starting main recipes thread")
    main_recipes_thread = threading.Thread(target=main_recipes_loop,
                                           name="main_recipes")
    main_recipes_thread.daemon = True
    main_recipes_thread.start()

    try:
        while True:
            time.sleep(20)
            running_threads = set([t.name for t in threading.enumerate()])
            if not running_threads.issuperset(beakerd_threads):
                log.critical("a thread has died, shutting down")
                rc = 1
                running = False
                event.set()
                break
            event.set()
            event.clear()
    except (SystemExit, KeyboardInterrupt):
       log.info("shutting down")
       running = False
       event.set()
       rc = 0

    if _threadpool_executor:
        _threadpool_executor.shutdown()
    interface.stop()
    main_recipes_thread.join(10)

    sys.exit(rc)