Beispiel #1
0
    def handle_exception(self, exception, debug):

        exc_type, exc_value, exc_traceback = sys.exc_info()
        filename, line_num, func_name, text = traceback.extract_tb(exc_traceback)[-1]
        message = exception.message
        warning = False

        self.response.status_int = 500

        if hasattr(exception, 'status_int'):
            self.response.status_int = exception.status_int

        self.response.status_message = message

        #  409 http status code conflict, meaning the user sent invalid data and should be able to change and resubmit
        if self.response.status_int == 409:
            warning = True

        if warning:
            logging.warning(message)
        else:
            data = self.clean_request_environ()
            data = pretty_json(data)
            logs = locals()
            logs['filename'] = '.'.join(logs['filename'].split('/')[-3:])
            logging.exception(exec_format, logs)

        return {"error": exception.message, 'status': self.response.status, 'status_int': self.response.status_int}
 def _log_task(task, queue_name):
     data = {
         'url': task.url,
         'method': task.method,
         'queue': queue_name,
         'eta': str(task.eta_posix),
         'payload': json.loads(task.payload)
     }
     logging.info('task: {}'.format(pretty_json(data)))
    def parse_json(self):

        if self.request.method not in JSON_METHODS:
            return None

        body = self.request.body

        try:
            self.json = json.loads(body)

            log = pretty_json(self.json)
            logging.info('body: {}'.format(log))
            self.created_by()

        except ValueError:
            logging.info('body: {}'.format(body))
            pass
    def push_task(self, url, method, payload=None, queue=constants.DEFAULT_QUEUE, eta=None, countdown=None, log=True):

        queue_list = self._get_queue(queue)

        if isinstance(payload, dict):
            payload = pretty_json(payload)

        task = Task(
            url=url,
            method=method,
            payload=payload,
            eta=eta,
            countdown=countdown
        )
        if log:
            self._log_task(task, queue)
        queue_list.append(task)
Beispiel #5
0
    def parse_json(self):

        if self.request.method not in JSON_METHODS:
            return None

        body = self.request.body

        try:
            self.json = json.loads(body)

            blob_key = self.json.get('blob_key')
            if blob_key:
                self.blob_info = BlobInfo.get(BlobKey(blob_key))

            log = pretty_json(self.json)
            logging.info('body: {}'.format(log))

        except ValueError:
            logging.info('body: {}'.format(body))
def add_task(url, method, payload=None, params=None, queue=constants.DEFAULT_QUEUE, eta=None, countdown=None):

    if isinstance(payload, dict):
        payload = pretty_json(payload)
        logging.info('payload: {}'.format(payload))

    if queue is None:
        queue = 'default'

    task = Task(
        url=url,
        method=method,
        payload=payload,
        params=params,
        eta=eta,
        countdown=countdown
    )

    if params:
        logging.info('params: {}'.format(task.extract_params()))

    task.add(queue_name=queue)
    def format_resp(self, resp):

        if self.sending_file or hasattr(self, 'template_file'):
            return

        if not isinstance(resp, list):
            resp = resp or {}

        self.response.headers['Content-Type'] = 'application/json'
        if self.headers:
            self.response.headers.update(self.headers)

        if isinstance(resp, basestring):
            self.response.headers['Content-Type'] = 'text/plain'
            write = resp

        elif isinstance(resp, JSON_TYPES):
            if type(resp) == tuple:
                resp = dict(
                    results=resp[0],
                    cursor=resp[1],
                    found=resp[2],
                    count=resp[3]
                )

            if self.pretty:
                write = pretty_json(resp)
            else:
                write = json.dumps(resp)

        else:
            error = {'error': 'format response type failure'}
            write = json.dumps(error)
            logging.exception(error['error'])

        req_time = str((datetime.today() - self.start_time))
        logging.info('{} {}'.format(req_time, write))
        self.response.out.write(write)