コード例 #1
0
    def test_fetch_batch(self):
        """Test fetching a batch of messages"""
        class MockQueue:
            def get_messages(self, *args, **kwargs):
                return []

        with mock.patch('boto.sqs') as mock_sqs:
            mock_sqs.connect_to_region.return_value = mock.MagicMock()
            mock_sqs.connection.SQSConnection.return_value = mock.MagicMock()
            mock_sqs.connect_to_region.lookup.return_value = MockQueue()
            mock_sqs.connection.SQSConnection.lookup.return_value = MockQueue()
            mock_consumer = consumer.Consumer()
            self.assertIsNotNone(
                mock_consumer.fetch_batch(settings.QUEUE_CLASS, 0, 60))
            self.assertIsNotNone(
                mock_consumer.fetch_batch(settings.QUEUE_CLASS, 0, 60, 10))
コード例 #2
0
ファイル: worker.py プロジェクト: corydolphin/ndkale
    def __init__(self):
        """Initialize a worker instance."""

        self._consumer = consumer.Consumer()

        queue_class = utils.class_import_from_path(settings.QUEUE_CLASS)
        q_info = queue_info.QueueInfo(
            config_file=settings.QUEUE_CONFIG,
            sqs_talk=self._consumer,
            queue_cls=queue_class)

        queue_selector_class = utils.class_import_from_path(
            settings.QUEUE_SELECTOR)
        self._queue_selector = queue_selector_class(q_info)

        # The worker will publish permanently failed tasks to a
        # dead-letter-queue.
        self._publisher = self._get_publisher()

        # Track total messages processed.
        self._total_messages_processed = 0

        # Intialize queue variables used by each batch.
        self._incomplete_messages = []
        self._successful_messages = []
        self._failed_messages = []
        self._permanent_failures = []
        self._batch_stop_time = time.time()
        self._batch_queue = None
        # Monitors whether the worker has been exposed to tasks and may
        # have bloated in memory.
        self._dirty = False

        # Setup signal handling for cleanup.
        for sig in SIGNALS_TO_HANDLE:
            signal.signal(sig, self._cleanup_worker)

        # Allow the client of this library to do any setup before
        # starting the worker.
        settings.ON_WORKER_STARTUP()
コード例 #3
0
ファイル: test_consumer.py プロジェクト: teeparham/ndkale
    def test_fetch_batch(self):
        c = consumer.Consumer()

        self.assertIsNotNone(c.fetch_batch(settings.QUEUE_CLASS, 10, 60))
        self.assertIsNotNone(c.fetch_batch(settings.QUEUE_CLASS, 10, 60, 2))