コード例 #1
0
    def _context(self,
                 sig,
                 rate_limits=True,
                 events=True,
                 utc=True,
                 limit=None):
        self.assertTrue(sig.type.Strategy)

        reserved = Mock()
        consumer = Mock()
        consumer.task_buckets = defaultdict(lambda: None)
        if limit:
            bucket = TokenBucket(rate(limit), capacity=1)
            consumer.task_buckets[sig.task] = bucket
        consumer.controller.state.revoked = set()
        consumer.disable_rate_limits = not rate_limits
        consumer.event_dispatcher.enabled = events
        s = sig.type.start_strategy(self.app, consumer, task_reserved=reserved)
        self.assertTrue(s)

        message = task_message_from_sig(
            self.app,
            sig,
            utc=utc,
            TaskMessage=self.get_message_class(),
        )
        message = self.prepare_message(message)
        yield self.Context(sig, s, reserved, consumer, message)
コード例 #2
0
 def get_request(self, sig, Request=Request, **kwargs):
     return Request(task_message_from_sig(self.app, sig),
                    on_ack=Mock(name='on_ack'),
                    on_reject=Mock(name='on_reject'),
                    eventer=Mock(name='eventer'),
                    app=self.app,
                    connection_errors=(socket.error, ),
                    task=sig.type,
                    **kwargs)
コード例 #3
0
ファイル: test_request.py プロジェクト: hanshoudong/celery
 def get_request(self, sig, Request=Request, **kwargs):
     return Request(
         task_message_from_sig(self.app, sig),
         on_ack=Mock(name='on_ack'),
         on_reject=Mock(name='on_reject'),
         eventer=Mock(name='eventer'),
         app=self.app,
         connection_errors=(socket.error,),
         task=sig.type,
         **kwargs
     )
コード例 #4
0
ファイル: test_strategy.py プロジェクト: 343829084/celery
    def _context(self, sig,
                 rate_limits=True, events=True, utc=True, limit=None):
        self.assertTrue(sig.type.Strategy)

        reserved = Mock()
        consumer = Mock()
        consumer.task_buckets = defaultdict(lambda: None)
        if limit:
            bucket = TokenBucket(rate(limit), capacity=1)
            consumer.task_buckets[sig.task] = bucket
        consumer.controller.state.revoked = set()
        consumer.disable_rate_limits = not rate_limits
        consumer.event_dispatcher.enabled = events
        s = sig.type.start_strategy(self.app, consumer, task_reserved=reserved)
        self.assertTrue(s)

        message = task_message_from_sig(self.app, sig, utc=utc)
        yield self.Context(sig, s, reserved, consumer, message)
コード例 #5
0
ファイル: test_loops.py プロジェクト: xn8x/celery
 def task_context(self, sig, **kwargs):
     x, on_task = get_task_callback(self.app, **kwargs)
     message = task_message_from_sig(self.app, sig)
     strategy = x.obj.strategies[sig.task] = Mock(name='strategy')
     return x, on_task, message, strategy
コード例 #6
0
ファイル: test_loops.py プロジェクト: aidan/celery
 def task_context(self, sig, **kwargs):
     x, on_task = get_task_callback(self.app, **kwargs)
     message = task_message_from_sig(self.app, sig)
     strategy = x.obj.strategies[sig.task] = Mock(name='strategy')
     return x, on_task, message, strategy