-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added missing/stale worker threshold (#14)
- Loading branch information
Showing
5 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
from datetime import datetime, timedelta | ||
|
||
class Worker(): | ||
last_check_in = None | ||
|
||
def __init__(self): | ||
self.check_in() | ||
|
||
def check_in(self): | ||
self.last_check_in = datetime.utcnow() | ||
|
||
def is_stale(self): | ||
threshold = int(os.getenv("MISSING_WORKER_THRESHOLD", 5)) | ||
# When threshold is 0, the worker is never stale | ||
if threshold == 0: | ||
return False | ||
return self.last_check_in < datetime.utcnow() - timedelta(seconds=threshold) | ||
|
||
worker = Worker() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters