"""Utility to dump events to screen.This is a simple program that dumps events to the consoleas they happen. Think of it like a `tcpdump` for Celery events."""importsysfromdatetimeimportdatetimefromcelery.appimportapp_or_defaultfromcelery.utils.functionalimportLRUCachefromcelery.utils.timeimporthumanize_seconds__all__=('Dumper','evdump')TASK_NAMES=LRUCache(limit=0xFFF)HUMAN_TYPES={'worker-offline':'shutdown','worker-online':'started','worker-heartbeat':'heartbeat',}CONNECTION_ERROR="""\-> Cannot connect to %s: %s.Trying again %s"""defhumanize_type(type):try:returnHUMAN_TYPES[type.lower()]exceptKeyError:returntype.lower().replace('-',' ')
[文档]defsay(self,msg):print(msg,file=self.out)# need to flush so that output can be piped.try:self.out.flush()exceptAttributeError:# pragma: no coverpass