def __call__(self, *args, **kwargs): # Add logger self.logger = LogHelper(self) # Add DB Helper self.db = MySQLHelper(self.logger) # Add Cache Helper self.cache_db = RedisHelper(self.logger) # Run try: return super(BaseResultSavingTask, self).__call__(*args, **kwargs) except Exception as e: for line in traceback.format_exc().splitlines(): self.logger.error(line) raise
def colored(s, color=None): if not color: color = 'yellow' color = COLOR_MAP[color] return color + '{}\033[0m'.format(s) class CommandCanceledException(Exception): pass CONFIG = yaml_resources.get('CONFIG') DB = MySQLHelper(logging) CACHE_DB = RedisHelper(logging) ADMIN_USER_ID = 'u-admin' DB_UPGRADE_SEQ_ID = 'upgrade.db.upgradeSeq' COMMAND_FUNCS = {} def command(F): COMMAND_FUNCS[F.__name__] = F return F def confirm(): # 确认
def __call__(self, *args, **kwargs): # Add logger self.logger = LogHelper(self) # Add DB Helper self.db = MySQLHelper(self.logger) # Add Cache Helper self.cache_db = RedisHelper(self.logger) # Add File Storage Helper self.file_storage = FileSystemHelper(self.logger) if CONFIG['MODE'] == 'prod': self.db.skip_log = True self.cache_db.skip_log = True # Add extra information if not self.request.called_directly: self._set_task_status(celery_status.PENDING, x_start_time=int(time.time()), x_end_time=None, x_retval=None, x_einfo_text=None, x_exception_message=None, x_exception_dump=None) # Sleep delay if 'sleepDelay' in kwargs: sleep_delay = 0 try: sleep_delay = float(kwargs['sleepDelay']) self.logger.debug( '[SLEEP DELAY] {} seconds...'.format(sleep_delay)) except Exception as e: for line in traceback.format_exc().splitlines(): self.logger.error(line) else: time.sleep(sleep_delay) # Run try: if LOG_CALL_ARGS: args_dumps = toolkit.json_safe_dumps(args, indent=None) if len(args_dumps) > LIMIT_ARGS_DUMP: args_dumps = args_dumps[0:LIMIT_ARGS_DUMP - 3] + '...' kwargs_dumps = toolkit.json_safe_dumps(kwargs, indent=None) if len(kwargs_dumps) > LIMIT_ARGS_DUMP: kwargs_dumps = kwargs_dumps[0:LIMIT_ARGS_DUMP - 3] + '...' self.logger.debug('[CALL] args: `{}`; kwargs: `{}`'.format( args_dumps, kwargs_dumps)) return super(BaseTask, self).__call__(*args, **kwargs) except (SoftTimeLimitExceeded, TimeLimitExceeded) as e: raise except Exception as e: for line in traceback.format_exc().splitlines(): self.logger.error(line) raise
def __call__(self, *args, **kwargs): # Add Queue Info self.worker_queue = self.request.delivery_info['routing_key'] self.queue = self.worker_queue.split('@').pop() # Add logger self.logger = LogHelper(self) # Add DB Helper self.db = MySQLHelper(self.logger) # Add Cache Helper self.cache_db = RedisHelper(self.logger) # Add File Storage Helper self.file_storage = FileSystemHelper(self.logger) if CONFIG['MODE'] == 'prod': self.db.skip_log = True self.cache_db.skip_log = True # Add extra information if not self.request.called_directly: self._set_task_status(celery_status.PENDING, x_start_time=int(time.time()), x_end_time=None, x_retval=None, x_einfo_text=None, x_exception_message=None, x_exception_dump=None) # Sleep delay if 'sleepDelay' in kwargs: sleep_delay = 0 try: sleep_delay = float(kwargs['sleepDelay']) self.logger.debug( '[SLEEP DELAY] {} seconds...'.format(sleep_delay)) except Exception as e: for line in traceback.format_exc().splitlines(): self.logger.error(line) else: time.sleep(sleep_delay) # Run try: task_info = '`{}`'.format(self.name) func_id = kwargs.get('funcId') if func_id: task_info = '`{}`'.format(func_id) + '@' + task_info self.logger.debug('[CALL] {}'.format(task_info)) return super(BaseTask, self).__call__(*args, **kwargs) except (SoftTimeLimitExceeded, TimeLimitExceeded) as e: raise except Exception as e: for line in traceback.format_exc().splitlines(): self.logger.error(line) raise