예제 #1
0
    def __init__(self, config):
        self.queue_cycle = cycle_by_name('round_robin')()
        self.queue_config = config
        self._set_initial_state()

        self.level_lookup_table = {}
        for level, queues in config.items():
            for q in queues:
                self.level_lookup_table[q] = level
예제 #2
0
def test_sorted_cycle():
    it = cycle_by_name('sorted')(['B', 'C', 'A'])
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('B')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('C')
    assert it.consume(3) == ['A', 'B', 'C']
예제 #3
0
def test_priority_cycle():
    it = cycle_by_name('priority')(['A', 'B', 'C'])
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('B')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('C')
    assert it.consume(3) == ['A', 'B', 'C']
예제 #4
0
def test_round_robin_cycle():
    it = cycle_by_name('round_robin')(['A', 'B', 'C'])
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('B')
    assert it.consume(3) == ['A', 'C', 'B']
    it.rotate('A')
    assert it.consume(3) == ['C', 'B', 'A']
    it.rotate('A')
    assert it.consume(3) == ['C', 'B', 'A']
    it.rotate('C')
    assert it.consume(3) == ['B', 'A', 'C']
예제 #5
0
 def test_priority_cycle(self):
     it = cycle_by_name('priority')(['A', 'B', 'C'])
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('B')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('A')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('A')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('C')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
예제 #6
0
 def test_round_robin_cycle(self):
     it = cycle_by_name('round_robin')(['A', 'B', 'C'])
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('B')
     self.assertListEqual(it.consume(3), ['A', 'C', 'B'])
     it.rotate('A')
     self.assertListEqual(it.consume(3), ['C', 'B', 'A'])
     it.rotate('A')
     self.assertListEqual(it.consume(3), ['C', 'B', 'A'])
     it.rotate('C')
     self.assertListEqual(it.consume(3), ['B', 'A', 'C'])
예제 #7
0
 def test_sorted_cycle(self):
     it = cycle_by_name('sorted')(['B', 'C', 'A'])
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('B')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('A')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('A')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
     it.rotate('C')
     self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
예제 #8
0
def test_sorted_cycle():
    it = cycle_by_name('sorted')(['B', 'C', 'A'])
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('B')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('C')
    assert it.consume(3) == ['A', 'B', 'C']
예제 #9
0
def test_priority_cycle():
    it = cycle_by_name('priority')(['A', 'B', 'C'])
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('B')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('A')
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('C')
    assert it.consume(3) == ['A', 'B', 'C']
예제 #10
0
def test_round_robin_cycle():
    it = cycle_by_name('round_robin')(['A', 'B', 'C'])
    assert it.consume(3) == ['A', 'B', 'C']
    it.rotate('B')
    assert it.consume(3) == ['A', 'C', 'B']
    it.rotate('A')
    assert it.consume(3) == ['C', 'B', 'A']
    it.rotate('A')
    assert it.consume(3) == ['C', 'B', 'A']
    it.rotate('C')
    assert it.consume(3) == ['B', 'A', 'C']
예제 #11
0
    def __init__(self, *args, **kwargs):
        super_ = super(Channel, self)
        super_.__init__(*args, **kwargs)

        if not self.ack_emulation:  # disable visibility timeout
            self.QoS = virtual.QoS

        self._queue_cycle = cycle_by_name(self.queue_order_strategy)()
        self.Client = self._get_client()
        self.ResponseError = self._get_response_error()
        self.active_fanout_queues = set()
        self.auto_delete_queues = set()
        self._fanout_to_queue = {}
        self.handlers = {'BRPOP': self._brpop_read, 'LISTEN': self._receive}

        if self.fanout_prefix:
            if isinstance(self.fanout_prefix, string_t):
                self.keyprefix_fanout = self.fanout_prefix
        else:
            # previous versions did not set a fanout, so cannot enable
            # by default.
            self.keyprefix_fanout = ''

        # Evaluate connection.
        try:
            self.client.info()
        except Exception:
            self._disconnect_pools()
            raise

        self.connection.cycle.add(self)  # add to channel poller.
        # copy errors, in case channel closed but threads still
        # are still waiting for data.
        self.connection_errors = self.connection.connection_errors

        if register_after_fork is not None:
            register_after_fork(self, _after_fork_cleanup_channel)
예제 #12
0
파일: redis.py 프로젝트: IthacaDream/kombu
    def __init__(self, *args, **kwargs):
        super_ = super(Channel, self)
        super_.__init__(*args, **kwargs)

        if not self.ack_emulation:  # disable visibility timeout
            self.QoS = virtual.QoS

        self._queue_cycle = cycle_by_name(self.queue_order_strategy)()
        self.Client = self._get_client()
        self.ResponseError = self._get_response_error()
        self.active_fanout_queues = set()
        self.auto_delete_queues = set()
        self._fanout_to_queue = {}
        self.handlers = {'BRPOP': self._brpop_read, 'LISTEN': self._receive}

        if self.fanout_prefix:
            if isinstance(self.fanout_prefix, string_t):
                self.keyprefix_fanout = self.fanout_prefix
        else:
            # previous versions did not set a fanout, so cannot enable
            # by default.
            self.keyprefix_fanout = ''

        # Evaluate connection.
        try:
            self.client.info()
        except Exception:
            self._disconnect_pools()
            raise

        self.connection.cycle.add(self)  # add to channel poller.
        # copy errors, in case channel closed but threads still
        # are still waiting for data.
        self.connection_errors = self.connection.connection_errors

        if register_after_fork is not None:
            register_after_fork(self, _after_fork_cleanup_channel)
예제 #13
0
 def __init__(self):
     self.cycle = cycle_by_name('round_robin')()