From abfcaa29fc619b58cf6f90ded501f39de413c178 Mon Sep 17 00:00:00 2001 From: Florian Dematraz Date: Wed, 27 Oct 2021 00:48:42 +0900 Subject: [PATCH] TinyDB fixes --- .github/workflows/release.yml | 7 ++++++- CHANGELOG.md | 7 +++++++ VERSION | 2 +- snooze/db/file/database.py | 14 +++++++++----- web/package.json | 2 +- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14486f09..4396e9a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -150,8 +150,13 @@ jobs: venvctrl mkdir /var/tmp/BUILD /var/tmp/SOURCES /var/tmp/SRPMS/ /var/tmp/RPMS - name: Build RPM + uses: nick-invision/retry@v2 id: rpm-build - run: rpmbuild --bb snooze-server.spec + with: + retry_on: error + max_attempts: 3 + timeout_minutes: 10 + command: rpmbuild --bb snooze-server.spec - name: package_path run: echo "::set-output name=package_path::$(echo /var/tmp/RPMS/x86_64/snooze-server-$(cat VERSION)-1.x86_64.rpm)" id: package_path diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a69c90..e12eed05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v1.0.16 + +### Bug fixes +* TinyDB was broken since v1.0.11 +* Date was handled incorrectly for TinyDB metric features +* Github CI fix + ## v1.0.15 ### New features diff --git a/VERSION b/VERSION index a9707166..b668c3b2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.15 +1.0.16 diff --git a/snooze/db/file/database.py b/snooze/db/file/database.py index 68f1e893..ecc94d71 100644 --- a/snooze/db/file/database.py +++ b/snooze/db/file/database.py @@ -11,8 +11,8 @@ from snooze.utils.functions import dig, flatten, to_tuple from threading import Lock from logging import getLogger +from datetime import datetime import uuid -import datetime import re log = getLogger('snooze.db.file') @@ -33,6 +33,7 @@ def test_root(self, func, *args): allow_empty_path=True ) + def test_contains(array, value): if not isinstance(array, list): array = [array] @@ -56,10 +57,13 @@ def init_db(self, conf): log.debug("Initialized TinyDB at path {}".format(filename)) log.debug("db: {}".format(self.db)) + def create_index(self, collection, fields): + pass + def cleanup_timeout(self, collection): mutex.acquire() #log.debug("Cleanup collection {}".format(collection)) - now = datetime.datetime.now().timestamp() + now = datetime.now().timestamp() aggregate_results = self.db.table(collection).search(Query().ttl >= 0) aggregate_results = list(map(lambda doc: {'_id': doc.doc_id, 'timeout': doc['ttl'] + doc['date_epoch']}, aggregate_results)) aggregate_results = list(filter(lambda doc: doc['timeout'] <= now, aggregate_results)) @@ -108,7 +112,7 @@ def write(self, collection, obj, primary = None, duplicate_policy='update', upda for o in tobj: primary_docs = None if update_time: - o['date_epoch'] = datetime.datetime.now().timestamp() + o['date_epoch'] = datetime.now().timestamp() if primary and all(dig(o, *p.split('.')) for p in primary): primary_query = map(lambda a: dig(Query(), *a.split('.')) == dig(o, *a.split('.')), primary) primary_query = reduce(lambda a, b: a & b, primary_query) @@ -178,7 +182,7 @@ def write(self, collection, obj, primary = None, duplicate_policy='update', upda return {'data': {'added': deepcopy(added), 'updated': deepcopy(updated), 'replaced': deepcopy(replaced),'rejected': deepcopy(rejected)}} def inc(self, collection, field, labels={}): - now = int((datetime.datetime.now().timestamp() // 3600) * 3600) + now = int((datetime.now().timestamp() // 3600) * 3600) table = self.db.table(collection) query = Query() mutex.acquire() @@ -251,7 +255,7 @@ def compute_stats(self, collection, date_from, date_until, groupby='hour'): groups = {} res = [] for doc in results: - date_range = datetime.date.fromtimestamp(doc['date']).strftime(date_format) + date_range = datetime.fromtimestamp(doc['date']).astimezone().strftime(date_format) if date_range not in groups: groups[date_range] = {doc['key']: {'value': 0}} elif doc['key'] not in groups[date_range]: diff --git a/web/package.json b/web/package.json index b4838d9b..b24ffa53 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "snooze-web", - "version": "1.0.15", + "version": "1.0.16", "description": "", "author": "", "homepage": "",