Esempio n. 1
0
class Scheduler(object):
    def __init__(self, config_file):
        self.logger = logging.getLogger('cachet_url_monitor.scheduler.Scheduler')
        self.configuration = Configuration(config_file)
        self.agent = self.get_agent()

        self.stop = False

    def get_agent(self):
        action_names = {
            'CREATE_INCIDENT': CreateIncidentDecorator,
            'UPDATE_STATUS': UpdateStatusDecorator,
        }
        actions = []
        for action in self.configuration.get_action():
            self.logger.info('Registering action %s' % (action))
            actions.append(action_names[action]())
        return Agent(self.configuration, decorators=actions)

    def start(self):
        self.agent.start()
        self.logger.info('Starting monitor agent...')
        while not self.stop:
            schedule.run_pending()
            time.sleep(self.configuration.data['frequency'])
Esempio n. 2
0
class Scheduler(object):
    def __init__(self, config_file):
        self.logger = logging.getLogger(
            'cachet_url_monitor.scheduler.Scheduler')
        self.configuration = Configuration(config_file)
        self.agent = self.get_agent()

        self.stop = False

    def get_agent(self):
        action_names = {
            'CREATE_INCIDENT': CreateIncidentDecorator,
            'UPDATE_STATUS': UpdateStatusDecorator,
        }
        actions = []
        for action in self.configuration.get_action():
            self.logger.info('Registering action %s' % (action))
            actions.append(action_names[action]())
        return Agent(self.configuration, decorators=actions)

    def start(self):
        self.agent.start()
        self.logger.info('Starting monitor agent...')
        while not self.stop:
            schedule.run_pending()
            time.sleep(self.configuration.data['frequency'])
def build_agent(configuration: Configuration, logger: logging.Logger):
    actions: List[Decorator] = []
    for action in configuration.get_action():
        logger.info(f"Registering action {action}")
        actions.append(ACTION_NAMES_DECORATOR_MAP[action]())
    return Agent(configuration, decorators=actions)