Skip to content

Commit

Permalink
TinyDB fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemega committed Oct 26, 2021
1 parent 384a119 commit abfcaa2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.15
1.0.16
14 changes: 9 additions & 5 deletions snooze/db/file/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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]
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snooze-web",
"version": "1.0.15",
"version": "1.0.16",
"description": "",
"author": "",
"homepage": "",
Expand Down

0 comments on commit abfcaa2

Please sign in to comment.