From 8a6503da8a4b2efe806ea4b00be9552827fe8ea9 Mon Sep 17 00:00:00 2001 From: Arksine Date: Sun, 18 Oct 2020 10:06:59 -0400 Subject: [PATCH] datastore: Add timestamp (in unix time) field to each line in the gcode store Signed-off-by: Eric Callahan --- moonraker/plugins/data_store.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/moonraker/plugins/data_store.py b/moonraker/plugins/data_store.py index 8687c4e..8f8858b 100644 --- a/moonraker/plugins/data_store.py +++ b/moonraker/plugins/data_store.py @@ -4,6 +4,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import logging +import time from collections import deque from tornado.ioloop import IOLoop, PeriodicCallback @@ -107,8 +108,8 @@ class DataStore: self.temp_update_cb.stop() def _update_gcode_store(self, response): - lines = response.strip().split("\n") - self.gcode_queue.extend(lines) + curtime = time.time() + self.gcode_queue.append({'message': response, 'time': curtime}) async def _handle_gcode_store_request(self, path, method, args): count = args.get("count", None) @@ -119,9 +120,9 @@ class DataStore: raise self.server.error( "Parameter must be an integer value, " f"received: {count}") - res = "\n".join(list(self.gcode_queue)[-count:]) + res = list(self.gcode_queue)[-count:] else: - res = "\n".join(list(self.gcode_queue)) + res = list(self.gcode_queue) return {'gcode_store': res} def load_plugin(config):