-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.py
41 lines (37 loc) · 1.29 KB
/
worker.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
import logging
from lib.app import app
from lib import worker
from lib import ml
from lib.db import DB
from time import sleep
from lib.camera import CameraDownError, NightTimeError
if __name__ == "__main__":
with app.app_context():
db = DB.get_db()
db.setup()
try:
logging.info("training model")
# Always try train on first boot.
ml.train(force=True)
logging.info("training complete")
except ml.NoTraingDataError as e:
logging.warning(e)
except Exception:
logging.exception("Unexpected error training model")
while True:
try:
worker.run()
except NightTimeError as e:
logging.warning(e)
logging.info("training model")
try:
ml.train()
except (ml.TrainingIntervalError, ml.NoTraingDataError) as e:
logging.warning(e)
except Exception:
logging.exception("Unexpected error training model")
except CameraDownError as e:
logging.warning(e)
except Exception:
logging.exception("Unexpected error running worker")
sleep(app.config["INTERVAL_CAMERA"])