示例#1
0
    def process_message(self, body, message):
        """
        gets called back once a message arrives in the work queue

            1. Sends email notifiactions once msg goes to dead letter queue

        :param body: message payload
        :param message: queued message with headers and other metadata
        """
        logger = logging.getLogger(self.__class__.__name__)
        job = EasyJob.create_from_dict(message.headers)

        try:
            response = job.notify_error(body, self.get_config().async_timeout)

            if response.status_code != 200:
                logger.error("Failed to notify with status code: {} with message: {}".format(response.status_code,
                                                                                             response.message))
                self.log_to_file(response, job, body)
        except Exception as e:
            traceback.print_exc()
            err_msg = "Notification Failed for job {}".format(body)
            logger.error(err_msg)

        message.ack()
示例#2
0
    def process_message(self, body, message):
        """
        gets called back once a message arrives in the work queue

            1. calls embedded api with the payload as its parameters when a message arrives

            2. if the call is successful, acks the message
            3. for remote call 
                a. in case the call fails with 4XX, just acks the message, no further action
                b. in case the call fails with a 5XX,
                  - adds the error to error-log header
                  - if num-retries are more than max_retries,
                    - puts the message in dead-letter-queue
                  - else
                    - increases num-retries by 1
                    - puts the message in error-queue
            4. for local call
                a. in case the call fails with a exception then adds the call to a dead letter queue

        :param body: message payload
        :param message: queued message with headers and other metadata (contains a EasyJob object in headers)
        """
        logger = logging.getLogger(self.__class__.__name__)

        try:
            job = EasyJob.create_from_dict(message.headers)
        except easyjoblite.exception.UnableToCreateJob as e:
            logger.error(e.message + " data: " + str(e.data))
            message.ack()
            self.__push_raw_msg_to_dlq(body=body,
                                       message=message,
                                       err_msg=e.message,
                                       )
            return
        try:
            api = job.api
            logger.debug("recieved api: " + str(api))

            response = job.execute(body, self.get_config().async_timeout)

            message.ack()

            if response.status_code >= 400:
                # todo: we should have booking id here in the log message
                logger.info("{status}: {resp}".format(status=response.status_code,
                                                      resp=response.message))

                if response.status_code >= 500:
                    # we have a retry-able failure
                    self._push_message_to_error_queue(body=body, message=message, job=job)

                else:
                    # push not retry-able error to dlq
                    self._push_msg_to_dlq(body=body,
                                          message=message,
                                          job=job
                                          )
        except (Exception, easyjoblite.exception.ApiTimeoutException) as e:
            traceback.print_exc()
            logger.error(str(e))
            message.ack()
            self._push_message_to_error_queue(body, message, job)