#!/usr/bin/python3
# -*- coding: utf-8 -*-
from processors import Worker
from server_checker import ProducerProcess, AnalysisProcess
from bot import Bot


class Core(Worker):
    def __init__(self):
        super().__init__()
        self.logger.info(f'{self.__class__.__name__} initialize call...')
        self.producer = ProducerProcess(self)
        self.analysis = AnalysisProcess(self)
        self.bot = Bot()

    def run(self):
        self.producer.run()
        self.analysis.run()
        self.bot.run()

    def stop(self):
        self.producer.stop()
        self.analysis.stop()
        self.bot.stop()


if __name__ == '__main__':
    """ Mac 에서 멀티 프로세싱 관련 오류 날 경우 환경변수에 아래 항목 추가.
    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
    """
    try:
        global core
        core = Core()
        core.run()
    except KeyboardInterrupt as e:
        core.stop()
        print('Bye...')
    except Exception as e:
        print(e)
