Spaces:
Sleeping
Sleeping
Create policy/kill_switch.py
Browse files- policy/kill_switch.py +3 -20
policy/kill_switch.py
CHANGED
|
@@ -1,26 +1,9 @@
|
|
| 1 |
-
import time
|
| 2 |
-
|
| 3 |
class KillSwitch:
|
| 4 |
def __init__(self):
|
| 5 |
self.disabled = {}
|
| 6 |
-
self.cooldown = 3600 # 1 hour
|
| 7 |
|
| 8 |
def disable(self, agency, reason):
|
| 9 |
-
self.disabled[agency] =
|
| 10 |
-
"reason": reason,
|
| 11 |
-
"time": time.time()
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
def is_enabled(self, agency):
|
| 15 |
-
if agency not in self.disabled:
|
| 16 |
-
return True
|
| 17 |
-
|
| 18 |
-
elapsed = time.time() - self.disabled[agency]["time"]
|
| 19 |
-
if elapsed > self.cooldown:
|
| 20 |
-
del self.disabled[agency]
|
| 21 |
-
return True
|
| 22 |
-
|
| 23 |
-
return False
|
| 24 |
|
| 25 |
-
def
|
| 26 |
-
return self.disabled
|
|
|
|
|
|
|
|
|
|
| 1 |
class KillSwitch:
|
| 2 |
def __init__(self):
|
| 3 |
self.disabled = {}
|
|
|
|
| 4 |
|
| 5 |
def disable(self, agency, reason):
|
| 6 |
+
self.disabled[agency] = reason
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def enabled(self, agency):
|
| 9 |
+
return agency not in self.disabled
|