Add changed timeseries to queue

This commit is contained in:
Peter J. Holzer 2022-12-11 22:58:04 +01:00
parent 1e034f1a7f
commit caeaa0bf73
1 changed files with 4 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import time
class LTS: class LTS:
base_dir = "data" base_dir = "data"
queue_dir = "queue"
limit = 1000 limit = 1000
def __init__(self, description=None, id=None): def __init__(self, description=None, id=None):
@ -20,6 +21,7 @@ class LTS:
m.update(bytes(serialized_description, encoding="UTF-8")) m.update(bytes(serialized_description, encoding="UTF-8"))
id = m.hexdigest() id = m.hexdigest()
self.filename = self.base_dir + "/" + id self.filename = self.base_dir + "/" + id
self.id = id
try: try:
with open(self.filename, "r") as fh: with open(self.filename, "r") as fh:
fcntl.flock(fh, fcntl.LOCK_SH) fcntl.flock(fh, fcntl.LOCK_SH)
@ -57,6 +59,8 @@ class LTS:
fcntl.flock(fh, fcntl.LOCK_EX) fcntl.flock(fh, fcntl.LOCK_EX)
json.dump({"description": self.description, "data": self.data}, fh) json.dump({"description": self.description, "data": self.data}, fh)
fh.truncate() fh.truncate()
with open(self.queue_dir + "/" + self.id, "w") as fh:
pass
def rebuild_index(self): def rebuild_index(self):
t0 = time.time() t0 = time.time()