def _rcb(obj): if obj is None: return '<missing>' if isinstance(obj, string_t): return obj if isinstance(obj, tuple): cb, args = obj return reprcall(cb.__name__, args=args) return obj.__name__
def process_task(self, body, message): fun = body['fun'] args = body['args'] kwargs = body['kwargs'] logger.info('Got task: %s', reprcall(fun.__name__, args, kwargs)) try: fun(*args, **kwargs) except Exception as exc: logger.error('task raised exception: %r', exc) message.ack()
def process_task(self, body, message): fun = body['fun'] args = body['args'] kwargs = body['kwargs'] logger.info('Got task: %s', reprcall(fun.__name__, args, kwargs)) try: # 注意这个fun并未import,是直接从body中序列化出来,因为本地未import hello_task fun(*args, **kwargs) except Exception as exc: logger.error('task raised exception: %r', exc) message.ack()
def reprcall(self, *args, **kwargs): args, kwargs, _ = self._merge(args, kwargs, {}, force=True) return reprcall(self['task'], args, kwargs)
def __repr__(self): return '<{name}: {0.name} {call} {0.schedule}'.format( self, call=reprcall(self.task, self.args or (), self.kwargs or {}), name=type(self).__name__, )
def __repr__(self): return reprcall('ffwd', (), self._fields(weeks=self.weeks, weekday=self.weekday))
def test_reprcall(): assert reprcall('add', (2, 2), {'copy': True})
def test_reprcall(self): self.assertTrue( reprcall('add', (2, 2), {'copy': True}), )