-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaq_status.py
More file actions
70 lines (52 loc) · 1.6 KB
/
daq_status.py
File metadata and controls
70 lines (52 loc) · 1.6 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import logging
from sqlalchemy.exc import SQLAlchemyError
import db_model as db
import datetime
STATUS_RUNNING = 1
STATUS_OK = 1
"""
class DaqStatus - Manage Daq Status table
"""
class DaqStatus:
def __init__(self, env):
self.env = env
def flush_parameters(self):
# Get new session
session = self.env.Session()
try:
# Flush all old parameters
session.query(db.Daq_Status).delete()
# Commit
session.commit()
# Close
session.close()
except SQLAlchemyError as e:
session.rollback()
logging.critical("Error: {0}".format(e))
def update_parameter(self, parameter, status):
# Get new session
session = self.env.Session()
try:
# Get parameter object
record = session.query(db.Daq_Status)\
.filter(db.Daq_Status.parameter == parameter)\
.first()
if record is None:
# update value
record = db.Daq_Status()
record.parameter = parameter
record.status = status
record.ts = datetime.datetime.now()
session.add(record)
else:
record.status = status
record.ts = datetime.datetime.now()
# Commit
session.commit()
# Close
session.close()
return False
except SQLAlchemyError as e:
session.rollback()
logging.critical("Error: {0}".format(e))
return False