From 0fd6e5a7ae27688a6e89bdb3712f64bae08b39dc Mon Sep 17 00:00:00 2001 From: quentin on chickenita Date: Tue, 26 Sep 2023 15:05:04 +0200 Subject: [PATCH] FIX: websockets.exceptions.ConnectionClosedError: sent 1009 (message too big) for list_msgs --- pypeman/plugins/remoteadmin/views.py | 10 ++++++++-- pypeman/remoteadmin.py | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pypeman/plugins/remoteadmin/views.py b/pypeman/plugins/remoteadmin/views.py index e11eb2e..01306c3 100644 --- a/pypeman/plugins/remoteadmin/views.py +++ b/pypeman/plugins/remoteadmin/views.py @@ -80,7 +80,9 @@ async def stop_channel(request, ws=None): async def list_msgs(request, ws=None): """ - List first `count` messages from message store of specified channel. + List first `count` message infos from message store of specified channel. + Return list of dicts with the id, the status and the timestamp of the message + without the content. :params channelname: The channel name. @@ -112,8 +114,11 @@ async def list_msgs(request, ws=None): text=text, rtext=rtext) or [] for res in messages: + res["id"] = res["id"] + res["state"] = res.get("state", "UNKNOWN") res['timestamp'] = res['message'].timestamp_str() - res['message'] = res['message'].to_json() + if "message" in res: + res.pop("message") resp_dict = {'messages': messages, 'total': await chan.message_store.total()} if ws is not None: @@ -211,6 +216,7 @@ async def send_jsonrpcresp(self, message): async def backport_old_client(request): ws = RPCWebSocketResponse() + logger.debug("Receiving a request from the shell client (%r)", vars(request)) await ws.prepare(request) async for msg in ws: try: diff --git a/pypeman/remoteadmin.py b/pypeman/remoteadmin.py index 1ec3f46..834e1c0 100644 --- a/pypeman/remoteadmin.py +++ b/pypeman/remoteadmin.py @@ -6,6 +6,7 @@ import re import sys +from datetime import datetime # TODO use readline for history ? # import readline @@ -154,8 +155,14 @@ async def list_msgs(self, channel, start=0, count=10, order_by='timestamp', star text=text, rtext=rtext) or [] for res in messages: - res['timestamp'] = res['message'].timestamp_str() - res['message'] = res['message'].to_json() + timestamp = res['timestamp'] + if isinstance(timestamp, datetime): + timestamp = datetime.timestamp(timestamp) + res['timestamp'] = timestamp + res['id'] = res['id'] + res['state'] = res["state"] + if "message" in res: + res.pop("message") return {'messages': messages, 'total': await chan.message_store.total()} @@ -309,7 +316,8 @@ def list_msgs(self, channel, start=0, count=10, order_by='timestamp', start_dt=N result = self.send_command('list_msgs', list_msg_args) for m in result['messages']: - m['message'] = message.Message.from_json(m['message']) + if "message" in m: + m.pop("message") return result @@ -460,7 +468,6 @@ def do_list(self, channel, arg): to filter messages - to filter messages, you can pass text and rtext (string between double quotes) to filter messages - - to preview 100 firsts characters of the message payload, pass the argument `--preview` """ dquote_args_regex = r'\w+=".*?"' dquote_args = re.findall(dquote_args_regex, arg) @@ -473,7 +480,6 @@ def do_list(self, channel, arg): start, end, order_by = 0, 100, '-timestamp' start_dt = None end_dt = None - to_preview = False text = None rtext = None @@ -487,9 +493,6 @@ def do_list(self, channel, arg): if arg.startswith("end_dt="): end_dt = arg.split("=")[1] args.remove(arg) - if arg == "--preview": - to_preview = True - args.remove(arg) if arg.startswith("text="): text = arg.split("=", 1)[1] args.remove(arg) @@ -512,9 +515,7 @@ def do_list(self, channel, arg): print('No message yet.') for res in result['messages']: - print(res['message'].timestamp, res['id'], res['state']) - if to_preview: - print(res['message'].payload[:100]) + print(res['timestamp'], res['id'], res['state']) @_with_current_channel def do_replay(self, channel, arg):