You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
882B

  1. from traceback import format_exc
  2. from loguru import logger
  3. from enums.ExceptionEnum import ExceptionType
  4. from exception.CustomerException import ServiceException
  5. def get_no_block_queue(queue):
  6. eBody = None
  7. try:
  8. eBody = queue.get(block=False)
  9. except Exception:
  10. pass
  11. return eBody
  12. def get_block_queue(queue):
  13. eBody = None
  14. try:
  15. eBody = queue.get()
  16. except Exception:
  17. pass
  18. return eBody
  19. def put_queue(queue, result, requestId='1', timeout=30, is_throw_ex=True):
  20. try:
  21. queue.put(result, timeout=timeout)
  22. except Exception:
  23. if is_throw_ex:
  24. logger.error("添加队列异常:{}, requestId:{}", format_exc(), requestId)
  25. raise ServiceException(ExceptionType.SERVICE_INNER_EXCEPTION.value[0],
  26. ExceptionType.SERVICE_INNER_EXCEPTION.value[1])