Пример #1
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
          scheduler:
            name: Scheduler1
            debug_level: 0
            add_listeners: True
            remove_all_jobs: True
            
            jobstore:
                name:   mongo
                
                mongo:
                    collection: example_jobs
    
                redis:
                    jobs_key: example.jobs
                    run_times_key: example.run_times
    
                sqlalchemy:
                    url: sqlite:///jobs.sqlite
    
            threadpool:
                max_workers: 20
        
            processpool:
                max_workers: 5   
        
            job_defaults:
                coalesce: False
                max_instances: 3
          
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals("Scheduler1", scheduler_config.name)
        self.assertEquals(0, scheduler_config.debug_level)
        self.assertTrue(scheduler_config.add_listeners)
        self.assertTrue(scheduler_config.remove_all_jobs)

        self.assertIsNotNone(scheduler_config.jobstore)
        self.assertIsNotNone(scheduler_config.jobstore.jobstore)
        self.assertEquals("example_jobs", scheduler_config.jobstore.jobstore.collection)

        self.assertIsNotNone(scheduler_config.threadpool)
        self.assertEquals(20, scheduler_config.threadpool.max_workers)

        self.assertIsNotNone(scheduler_config.processpool)
        self.assertEquals(5, scheduler_config.processpool.max_workers)

        self.assertIsNotNone(scheduler_config.job_defaults)
        self.assertEquals(False, scheduler_config.job_defaults.coalesce)
        self.assertEquals(3, scheduler_config.job_defaults.max_instances)
Пример #2
0
 def __init__(self, name):
     super().__init__(name)
     self._bot_configs = []
     self._bot_configs.append(BotConfiguration("bot"))
     self._license_keys = None
     self._bot_selector = None
     self._scheduler = SchedulerConfiguration()
     self._renderer = None
Пример #3
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, bot_config, ".")

        self.assertIsNone(scheduler_config.name)
        self.assertEquals(0, scheduler_config.debug_level)
        self.assertFalse(scheduler_config.add_listeners)
        self.assertFalse(scheduler_config.remove_all_jobs)

        self.assertIsNone(scheduler_config.jobstore)
        self.assertIsNone(scheduler_config.threadpool)
        self.assertIsNone(scheduler_config.processpool)
        self.assertIsNone(scheduler_config.job_defaults)
Пример #4
0
    def test_create_scheduler_config_redis(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
          scheduler:
            name: Scheduler1
            debug_level: 0
            add_listeners: True
            remove_all_jobs: True

            jobstore:
                name:   redis

                redis:
                    jobs_key: example.jobs
                    run_times_key: example.run_times

            threadpool:
                max_workers: 20

            processpool:
                max_workers: 5   

            job_defaults:
                coalesce: False
                max_instances: 3

        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, bot_config, ".")

        config = scheduler_config.create_scheduler_config()
        print(config)
        self.assertIsNotNone(config)
Пример #5
0
class ClientConfigurationData(BaseContainerConfigurationData):
    def __init__(self, name):
        super().__init__(name)
        self._bot_configs = []
        self._bot_configs.append(BotConfiguration("bot"))
        self._license_keys = None
        self._bot_selector = None
        self._scheduler = SchedulerConfiguration()
        self._renderer = None

    @property
    def configurations(self):
        return self._bot_configs

    @property
    def license_keys(self):
        return self._license_keys

    @property
    def bot_selector(self):
        return self._bot_selector

    @property
    def scheduler(self):
        return self._scheduler

    @property
    def renderer(self):
        return self._renderer

    def load_configuration(self, configuration_file, section, bot_root):
        if section is not None:
            bot_names = configuration_file.get_multi_option(
                section, "bot", missing_value="bot")
            first = True
            for name in bot_names:
                if first is True:
                    config = self._bot_configs[0]
                    first = False
                else:
                    config = BotConfiguration(name)
                    self._bot_configs.append(config)
                config.load_configuration(configuration_file, bot_root)

            self._license_keys = configuration_file.get_option(
                section, "license_keys")
            if self._license_keys is not None:
                self._license_keys = self.sub_bot_root(self._license_keys,
                                                       bot_root)

            self._bot_selector = configuration_file.get_option(
                section, "bot_selector")

            self._scheduler.load_config_section(configuration_file, section,
                                                bot_root)

            self._renderer = configuration_file.get_option(section, "renderer")

        else:
            YLogger.warning(
                self,
                "No bot name defined for client [%s], defaulting to 'bot'.",
                self.section_name)
            self._bot_configs[0]._section_name = "bot"
            self._bot_configs[0].load_configuration(configuration_file,
                                                    bot_root)

    def to_yaml(self, data, defaults=True):
        if defaults is True:
            data['bot'] = 'bot'
            data['license_keys'] = "./config/license.keys"
            data['bot_selector'] = "programr.clients.client.DefaultBotSelector"
            data[self._scheduler.id] = {}
            self._scheduler.to_yaml(data[self._scheduler.id], defaults)
            data['renderer'] = "programr.clients.render.text.TextRenderer"
        else:
            data['bot'] = self._bot_configs[0].id
            data['license_keys'] = self.license_keys
            data['bot_selector'] = self.bot_selector
            data[self._scheduler.id] = {}
            self._scheduler.to_yaml(data[self._scheduler.id], defaults)
            data['renderer'] = self.renderer