def command_response_processor(self): """Process Terminal Response :return: """ def response_data_process(ch, method, properties, body): try: command_data = json.loads(body) command_processor = adapter.CommandProcessor(stage='response', command=command_data) command_processor.do() except natrix_exception.BaseException: natrix_exception.natrix_traceback() logger.error('Consume reponse data error: {}'.format(command_data)) finally: ch.basic_ack(delivery_tag=method.delivery_tag) with mqservice.MQService.get_purge_channel() as channel: try: adapter_settting.AdapterMQSetting.init_response_queue(channel) channel.basic_consume(consumer_callback=response_data_process, queue=adapter_settting.QUEUE_RESPONSE) channel.start_consuming() except Exception as e: natrix_exception.natrix_traceback() logger.error(u'{}'.format(e)) finally: logger.info('Task End! - {}'.format(self.name))
def post(self, request, format=None): feedback = {'permission': True} user = request.user_rbac.user group = request.user_rbac.group try: post_data = request.data serializer = organization_serializer.OrganizationSerializer( user=user, group=group, data=post_data) if serializer.is_valid(): serializer.save() else: logger.error('Create organization error: {}'.format( serializer.format_errors())) feedback['data'] = ErrorCode.parameter_invalid( 'Organization Creation', serializer.format_errors()) raise natrix_exception.ParameterInvalidException( parameter='Organization Creation') feedback['data'] = {'code': 200, 'message': u'职场添加成功!'} except natrix_exception.BaseException as e: logger.info(e.get_log()) except Exception as e: natrix_exception.natrix_traceback() logger.error('There is an uncatch expection: {}'.format(e)) feedback['data'] = ErrorCode.sp_code_bug(str(e)) return JsonResponse(data=feedback)
def post(self, request, format=None): feedback = {'permission': True} try: post_data = request.data serializer = common_serializer.TerminalFilterSerializer( data=post_data) if serializer.is_valid(): res = serializer.query_result() feedback['data'] = { 'code': 200, 'message': 'Terminal list info', 'info': res } else: logger.error('Parameter Error: {}'.format( serializer.format_errors())) feedback['data'] = ErrorCode.parameter_invalid( 'terminallist', reason=serializer.format_errors()) except Exception as e: natrix_exception.natrix_traceback() logger.error('Common terminal list post ERROR') feedback['data'] = ErrorCode.sp_code_bug( 'Common terminal list post') return JsonResponse(data=feedback)
def response_data_process(ch, method, properties, body): try: command_data = json.loads(body) command_processor = adapter.CommandProcessor(stage='response', command=command_data) command_processor.do() except natrix_exception.BaseException: natrix_exception.natrix_traceback() logger.error('Consume reponse data error: {}'.format(command_data)) finally: ch.basic_ack(delivery_tag=method.delivery_tag)
def messenger_guard(self, queue_name=conf.queue_name): def messenger_data_process(ch, method, properties, body): messenger_processor.delay(body) ch.basic_ack(delivery_tag=method.delivery_tag) try: channel = MQService.get_channel(queue_name, durable=True) channel.basic_consume(consumer_callback=messenger_data_process, queue=queue_name) channel.start_consuming() except Exception as e: natrix_exceptions.natrix_traceback() logger.error('Task ({name}) raise exception {exception}'.format( name=self.name, exception=e)) finally: logger.info('Task End!-{}'.format(self.name))