Example #1
0
def main():
    with open(sys.argv[1], 'r') as config_file:
        config = yaml.safe_load(config_file)

    init_notifier(config)
    if 'metrics' in config:
        metrics.init(
            config, 'oncall-notifier', {
                'message_blackhole_cnt': 0,
                'message_sent_cnt': 0,
                'message_fail_cnt': 0
            })
        spawn(metrics_sender)
    else:
        logger.warning('Not running with metrics')

    init_messengers(config.get('messengers', []))

    worker_tasks = [spawn(worker) for x in xrange(100)]
    if config['reminder']['activated']:
        spawn(reminder.reminder, config['reminder'])
    if config['user_validator']['activated']:
        spawn(user_validator.user_validator, config['user_validator'])

    interval = 60

    logger.info('[*] notifier bootstrapped')
    while True:
        runtime = int(time.time())
        logger.info('--> notifier loop started.')
        poll()

        # check status for all background greenlets and respawn if necessary
        bad_workers = []
        for i, task in enumerate(worker_tasks):
            if not bool(task):
                logger.error("worker task failed, %s", task.exception)
                bad_workers.append(i)
        for i in bad_workers:
            worker_tasks[i] = spawn(worker)

        now = time.time()
        elapsed_time = now - runtime
        nap_time = max(0, interval - elapsed_time)
        logger.info(
            '--> notifier loop finished in %s seconds - sleeping %s seconds',
            elapsed_time, nap_time)
        sleep(nap_time)
Example #2
0
def main(config):
    global LDAP_SETTINGS

    LDAP_SETTINGS = config['ldap_sync']

    metrics.init(config, 'oncall-ldap-user-sync', stats)
    spawn(metrics_sender)
    # Default sleep one hour
    sleep_time = config.get('user_sync_sleep_time', 3600)
    engine = create_engine(config['db']['conn']['str'] % config['db']['conn']['kwargs'],
                           **config['db']['kwargs'])
    while 1:
        logger.info('Starting user sync loop at %s' % time.time())
        sync(config, engine)
        logger.info('Sleeping for %s seconds' % sleep_time)
        sleep(sleep_time)