changeset 1365:e6c6574f3d24

fix a hang bug where polling stopped Ignore-this: 7e3aaf37a2e0619c4b168cc424bf9c21 darcs-hash:f29bc74cf5a4f968bd45b9cf61e5fb5a430d9bed
author drewp <drewp@bigasterisk.com>
date Wed, 01 May 2019 00:24:13 -0700
parents 35dcf36bf395
children 5836e88a0287
files service/frontDoorLock/front_door_lock.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/service/frontDoorLock/front_door_lock.py	Wed May 01 00:09:54 2019 -0700
+++ b/service/frontDoorLock/front_door_lock.py	Wed May 01 00:24:13 2019 -0700
@@ -79,7 +79,7 @@
         self.timeUnlocked = None
         self.autoLockSec = 6 
         self.subj = ROOM['frontDoorLock']
-        task.LoopingCall(self.check).start(1)
+        task.LoopingCall(self.pollCheck).start(1)
 
     def relock(self):
         log.info('autolock is up: requesting lock')
@@ -90,9 +90,9 @@
         g = self.masterGraph
         lockIn = self.autoLockSec - int(unlockedFor)
         if lockIn < 0:
-            tu = self.timeUnlocked
-            log.warn("timeUnlocked %(tu)r, state %(state)s, "
-                     "unlockedFor %(unlockedFor)r, lockIn %(lockIn)r", vars())
+            state = g._graph.value(self.subj, ROOM['state'])
+            log.warn(f"timeUnlocked {self.timeUnlocked}, state {state}, "
+                     "unlockedFor {unlockedFor}, lockIn {lockIn}")
             lockIn = 0
         g.patchObject(ctx, self.subj, ROOM['unlockedForSec'],
                       Literal(int(unlockedFor)))
@@ -103,6 +103,12 @@
         g = self.masterGraph
         g.patchObject(ctx, self.subj, ROOM['unlockedForSec'], None)
         g.patchObject(ctx, self.subj, ROOM['autoLockInSec'], None)
+
+    def pollCheck(self):
+        try:
+            self.check()
+        except Exception:
+            log.exception('poll failed')
         
     def check(self):
         g = self.masterGraph