-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedulers.py
43 lines (37 loc) · 1.36 KB
/
schedulers.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
41
42
43
import schedule
import mysql.connector
import get_save_data as gsd
import time
import guli
import sys
def dbScheduler(host, user, passwd):
try:
db = mysql.connector.connect(
host = host,
user = user,
passwd = passwd)
cursor = db.cursor()
except:
print("Database connection error!")
sys.exit("Database connection error!")
schedule.every(2).minutes.do(gsd.getRobotOverview, db=db, cursor=cursor)
# Battery logger
schedule.every().second.do(gsd.getRobotLiveData, db=db, cursor=cursor)
schedule.every(2).seconds.do(gsd.getFromMirDB, db=db, cursor=cursor) # converts RobotLiveData to csv
# To DB
schedule.every().minute.do(gsd.getMaps, db=db, cursor=cursor)
schedule.every().minute.do(gsd.getPosDetails, db=db, cursor=cursor)
schedule.every().minute.do(gsd.getSoftwareLogs, db=db, cursor=cursor)
schedule.every(30).seconds.do(gsd.getErrorLogs, db=db, cursor=cursor)
while True:
schedule.run_pending()
time.sleep(1)
# When app shut down, clear jobs from schedule, close cursor and db connection
try:
if guli.GuliVariable("winClosed").get():
schedule.clear()
cursor.close()
db.close()
break
except:
pass