-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
40 lines (35 loc) · 1014 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import hashlib
import json
import time
def sha256(obj):
m = hashlib.sha256()
m.update(json.dumps(obj).encode())
return m.hexdigest()
class JobDTO:
"""
Entity stored in db.
"""
def __init__(self, study: dict(),
version: str = None,
created: int = 0,
computed: int = 0,
terminated: int = 0,
id: str = None,
status: str = 'QUEUED',
result: dict() = None,
error: str = ''):
self.created = created or int(time.time() * 1000)
self.computed = computed
self.terminated = terminated
self.status = status
self.id = id
self.version = version or study['version']
self.error = error
self.study = study
self.result = result
self.id = id or sha256(study)
def to_json(self):
return self.__dict__
@staticmethod
def from_json(dict):
return JobDTO(**dict)