def _create_request(self, task_id, name, args, kwargs, argsrepr=None, kwargsrepr=None, task_protocol=2): msg = self.app.amqp.task_protocols[task_protocol]( task_id=task_id, name=name, args=args, kwargs=kwargs, argsrepr=argsrepr, kwargsrepr=kwargsrepr, ) if task_protocol == 1: body, headers, _, _ = hybrid_to_proto2(msg, msg.body) properties = None sent_event = {} else: headers, properties, body, sent_event = msg context = Context( headers=headers, properties=properties, body=body, sent_event=sent_event, ) request = Request(context, decoded=True, task=name) if task_protocol == 1: assert request.argsrepr is None assert request.kwargsrepr is None else: assert request.argsrepr is not None assert request.kwargsrepr is not None return request
def test_execute_using_pool__defaults_of_hybrid_to_proto2(self): weakref_ref = Mock(name='weakref.ref') headers = strategy.hybrid_to_proto2('', {'id': uuid(), 'task': self.mytask.name})[1] job = self.zRequest(revoked_tasks=set(), ref=weakref_ref, **headers) job.execute_using_pool(self.pool) assert job._apply_result weakref_ref.assert_called_with(self.pool.apply_async()) assert job._apply_result is weakref_ref()
def task_message_handler( message: Message, body: Optional[Dict[str, Any]], ack: promise, reject: promise, callbacks: Set, **kw: Any, ) -> None: if body is None and "args" not in message.payload: body, headers, decoded, utc = ( message.body, message.headers, False, app.uses_utc_timezone(), ) else: if "args" in message.payload: body, headers, decoded, utc = hybrid_to_proto2( message, message.payload ) else: body, headers, decoded, utc = proto1_to_proto2(message, body) request = Req( message, on_ack=ack, on_reject=reject, app=app, hostname=hostname, eventer=eventer, task=task, body=body, headers=headers, decoded=decoded, utc=utc, connection_errors=connection_errors, ) put_buffer(request) if self._tref is None: # first request starts flush timer. self._tref = timer.call_repeatedly(self.flush_interval, flush_buffer) if not next(self._count) % self.flush_every: flush_buffer()
def test_retries_custom_value(self): _custom_value = 3 self.body['retries'] = _custom_value _, headers, _, _ = hybrid_to_proto2(self.message, self.body) assert headers.get('retries') == _custom_value
def test_retries_default_value(self): _, headers, _, _ = hybrid_to_proto2(self.message, self.body) assert headers.get('retries') == 0
def test_custom_headers(self): _, headers, _, _ = hybrid_to_proto2(self.message, self.body) assert headers.get("custom") == "header"