示例#1
0
def test_select_one_of_two_modules():
    config = {
        "module": "decisionengine.framework.taskmanager.tests.TwoSources",
        "name": "Source2",
        "parameters": {}
    }
    channelname = "test"
    _create_module_instance(config, Source, channelname)
示例#2
0
def test_no_module():
    config = {
        "module": "decisionengine.framework.taskmanager.tests.NoSource",
        "parameters": {}
    }
    channelname = "test"
    with pytest.raises(RuntimeError,
                       match="Could not find a decision-engine 'Source'"):
        _create_module_instance(config, Source, channelname)
示例#3
0
def test_too_many_modules():
    config = {
        "module": "decisionengine.framework.taskmanager.tests.TwoSources",
        "parameters": {}
    }
    channelname = "test"
    with pytest.raises(RuntimeError,
                       match="Found more than one decision-engine 'Source'"):
        _create_module_instance(config, Source, channelname)
示例#4
0
    def __init__(self, key, config, channel_name, exchange, broker_url):
        """
        :type config: :obj:`dict`
        :arg config: configuration dictionary describing the worker
        """
        super().__init__(name=f"SourceWorker-{key}")
        self.module_instance = _create_module_instance(config, Source, channel_name)
        self.config = config
        self.module = self.config["module"]
        self.key = key
        self.name = self.module_instance.__class__.__name__
        SOURCE_ACQUIRE_GAUGE.labels(self.name)

        self.logger = structlog.getLogger(LOGGERNAME)
        self.logger = self.logger.bind(module=__name__.split(".")[-1], source=self.name)

        self.exchange = exchange
        self.connection = Connection(broker_url)

        # We use a random name to avoid queue collisions when running tests
        queue_id = self.key + "-" + str(uuid.uuid4()).upper()
        self.logger.debug(f"Creating queue {queue_id} with routing key {self.key}")
        self.queue = Queue(
            queue_id,
            exchange=self.exchange,
            routing_key=self.key,
            auto_delete=True,
        )
        self.use_count = multiprocessing.Value("i", 1)
        self.schedule = config.get("schedule", _DEFAULT_SCHEDULE)

        self.logger.debug(
            f"Creating worker: module={self.module} name={self.key} class_name={self.name} parameters={config['parameters']} schedule={self.schedule}"
        )