datastore: Add timestamp (in unix time) field to each line in the gcode store

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-10-18 10:06:59 -04:00
parent ab35346f24
commit 8a6503da8a
1 changed files with 5 additions and 4 deletions

View File

@ -4,6 +4,7 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import logging import logging
import time
from collections import deque from collections import deque
from tornado.ioloop import IOLoop, PeriodicCallback from tornado.ioloop import IOLoop, PeriodicCallback
@ -107,8 +108,8 @@ class DataStore:
self.temp_update_cb.stop() self.temp_update_cb.stop()
def _update_gcode_store(self, response): def _update_gcode_store(self, response):
lines = response.strip().split("\n") curtime = time.time()
self.gcode_queue.extend(lines) self.gcode_queue.append({'message': response, 'time': curtime})
async def _handle_gcode_store_request(self, path, method, args): async def _handle_gcode_store_request(self, path, method, args):
count = args.get("count", None) count = args.get("count", None)
@ -119,9 +120,9 @@ class DataStore:
raise self.server.error( raise self.server.error(
"Parameter <count> must be an integer value, " "Parameter <count> must be an integer value, "
f"received: {count}") f"received: {count}")
res = "\n".join(list(self.gcode_queue)[-count:]) res = list(self.gcode_queue)[-count:]
else: else:
res = "\n".join(list(self.gcode_queue)) res = list(self.gcode_queue)
return {'gcode_store': res} return {'gcode_store': res}
def load_plugin(config): def load_plugin(config):