Skip to content

Commit

Permalink
FIX: websockets.exceptions.ConnectionClosedError: sent 1009 (message …
Browse files Browse the repository at this point in the history
…too big) for list_msgs
  • Loading branch information
quentin on chickenita committed Sep 26, 2023
1 parent 283e64f commit 0fc4890
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
9 changes: 7 additions & 2 deletions pypeman/plugins/remoteadmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 8 additions & 11 deletions pypeman/remoteadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ 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()
res['timestamp'] = res['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()}

Expand Down Expand Up @@ -309,7 +312,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

Expand Down Expand Up @@ -460,7 +464,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)
Expand All @@ -473,7 +476,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

Expand All @@ -487,9 +489,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)
Expand All @@ -512,9 +511,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):
Expand Down

0 comments on commit 0fc4890

Please sign in to comment.