How to use the oncall.api.v0.schedules.get_schedules function in oncall

To help you get started, we’ve selected a few oncall examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github linkedin / oncall / src / oncall / bin / scheduler.py View on Github external
schedulers = {}
        for row in db_cursor:
            try:
                scheduler_name = row['name']
                if scheduler_name not in schedulers:
                    schedulers[scheduler_name] = load_scheduler(scheduler_name)
            except (ImportError, AttributeError):
                logger.exception('Failed to load scheduler %s, skipping', row['name'])

        # Iterate through all teams
        db_cursor.execute('SELECT id, name, scheduling_timezone FROM team WHERE active = TRUE')
        teams = db_cursor.fetchall()
        for team in teams:
            logger.info('scheduling for team: %s', team['name'])
            schedule_map = defaultdict(list)
            for schedule in get_schedules({'team_id': team['id']}):
                schedule_map[schedule['scheduler']['name']].append(schedule)

            for scheduler_name, schedules in schedule_map.iteritems():
                schedulers[scheduler_name].schedule(team, schedules, (connection, db_cursor))

        # Sleep until next time
        sleep_time = cycle_time - (time.time() - start)
        if sleep_time > 0:
            logger.info('Sleeping for %s seconds' % sleep_time)
            time.sleep(cycle_time - (time.time() - start))
        else:
            logger.info('Schedule loop took %s seconds, skipping sleep' % (time.time() - start))

        db_cursor.close()
        connection.close()