Пример #1
0
    def add_event(self, event: Dict[str, Any]) -> None:
        if self.current_handler_id is not None:
            handler = get_handler_by_id(self.current_handler_id)
            async_request_timer_restart(handler._request)

        self.event_queue.push(event)
        self.finish_current_handler()
Пример #2
0
def finish_handler(handler_id: int, event_queue_id: str,
                   contents: List[Dict[str,
                                       Any]], apply_markdown: bool) -> None:
    err_msg = "Got error finishing handler for queue %s" % (event_queue_id, )
    try:
        # We call async_request_timer_restart here in case we are
        # being finished without any events (because another
        # get_events request has supplanted this request)
        handler = get_handler_by_id(handler_id)
        request = handler._request
        async_request_timer_restart(request)
        if len(contents) != 1:
            request._log_data['extra'] = "[%s/1]" % (event_queue_id, )
        else:
            request._log_data['extra'] = "[%s/1/%s]" % (event_queue_id,
                                                        contents[0]["type"])

        handler.zulip_finish(dict(result='success',
                                  msg='',
                                  events=contents,
                                  queue_id=event_queue_id),
                             request,
                             apply_markdown=apply_markdown)
    except IOError as e:
        if str(e) != 'Stream is closed':
            logging.exception(err_msg)
    except AssertionError as e:
        if str(e) != 'Request closed':
            logging.exception(err_msg)
    except Exception:
        logging.exception(err_msg)
Пример #3
0
def finish_handler(handler_id: int, event_queue_id: str,
                   contents: List[Dict[str,
                                       Any]], apply_markdown: bool) -> None:
    err_msg = f"Got error finishing handler for queue {event_queue_id}"
    try:
        # We call async_request_timer_restart here in case we are
        # being finished without any events (because another
        # get_events request has supplanted this request)
        handler = get_handler_by_id(handler_id)
        request = handler._request
        async_request_timer_restart(request)
        if len(contents) != 1:
            request._log_data["extra"] = f"[{event_queue_id}/1]"
        else:
            request._log_data["extra"] = "[{}/1/{}]".format(
                event_queue_id, contents[0]["type"])

        handler.zulip_finish(
            dict(result="success",
                 msg="",
                 events=contents,
                 queue_id=event_queue_id),
            request,
            apply_markdown=apply_markdown,
        )
    except OSError as e:
        if str(e) != "Stream is closed":
            logging.exception(err_msg, stack_info=True)
    except AssertionError as e:
        if str(e) != "Request closed":
            logging.exception(err_msg, stack_info=True)
    except Exception:
        logging.exception(err_msg, stack_info=True)
Пример #4
0
def finish_handler(handler_id: int, event_queue_id: str,
                   contents: List[Dict[str, Any]], apply_markdown: bool) -> None:
    err_msg = "Got error finishing handler for queue %s" % (event_queue_id,)
    try:
        # We call async_request_timer_restart here in case we are
        # being finished without any events (because another
        # get_events request has supplanted this request)
        handler = get_handler_by_id(handler_id)
        request = handler._request
        async_request_timer_restart(request)
        if len(contents) != 1:
            request._log_data['extra'] = "[%s/1]" % (event_queue_id,)
        else:
            request._log_data['extra'] = "[%s/1/%s]" % (event_queue_id, contents[0]["type"])

        handler.zulip_finish(dict(result='success', msg='',
                                  events=contents,
                                  queue_id=event_queue_id),
                             request, apply_markdown=apply_markdown)
    except IOError as e:
        if str(e) != 'Stream is closed':
            logging.exception(err_msg)
    except AssertionError as e:
        if str(e) != 'Request closed':
            logging.exception(err_msg)
    except Exception:
        logging.exception(err_msg)
Пример #5
0
    def add_event(self, event: Dict[str, Any]) -> None:
        if self.current_handler_id is not None:
            handler = get_handler_by_id(self.current_handler_id)
            async_request_timer_restart(handler._request)

        self.event_queue.push(event)
        self.finish_current_handler()
Пример #6
0
    def add_event(self, event: Dict[str, Any]) -> None:
        # Any dictionary passed into this function must be a unique
        # dictionary (potentially a shallow copy of a shared data
        # structure), since the event_queue data structures will
        # mutate it to add the queue-specific unique `id` of that
        # event to the outer event dictionary.
        if self.current_handler_id is not None:
            handler = get_handler_by_id(self.current_handler_id)
            async_request_timer_restart(handler._request)

        self.event_queue.push(event)
        self.finish_current_handler()
Пример #7
0
def finish_handler(handler_id: int, event_queue_id: str,
                   contents: List[Dict[str,
                                       Any]], apply_markdown: bool) -> None:
    err_msg = f"Got error finishing handler for queue {event_queue_id}"
    try:
        # We do the import during runtime to avoid cyclic dependency
        # with zerver.lib.request
        from zerver.lib.request import RequestNotes
        from zerver.middleware import async_request_timer_restart

        # We call async_request_timer_restart here in case we are
        # being finished without any events (because another
        # get_events request has supplanted this request)
        handler = get_handler_by_id(handler_id)
        request = handler._request
        async_request_timer_restart(request)
        log_data = RequestNotes.get_notes(request).log_data
        assert log_data is not None
        if len(contents) != 1:
            log_data["extra"] = f"[{event_queue_id}/1]"
        else:
            log_data["extra"] = "[{}/1/{}]".format(event_queue_id,
                                                   contents[0]["type"])

        tornado.ioloop.IOLoop.current().add_callback(
            handler.zulip_finish,
            dict(result="success",
                 msg="",
                 events=contents,
                 queue_id=event_queue_id),
            request,
            apply_markdown=apply_markdown,
        )
    except OSError as e:
        if str(e) != "Stream is closed":
            logging.exception(err_msg, stack_info=True)
    except AssertionError as e:
        if str(e) != "Request closed":
            logging.exception(err_msg, stack_info=True)
    except Exception:
        logging.exception(err_msg, stack_info=True)