a
This commit is contained in:
parent
0976a3e2ef
commit
9f229eae27
4 changed files with 7 additions and 4 deletions
0
LICENSE
Normal file → Executable file
0
LICENSE
Normal file → Executable file
0
Pipfile.lock
generated
Normal file → Executable file
0
Pipfile.lock
generated
Normal file → Executable file
0
setup.py
Normal file → Executable file
0
setup.py
Normal file → Executable file
|
@ -1,3 +1,5 @@
|
|||
import time
|
||||
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from os.path import join
|
||||
|
@ -25,18 +27,19 @@ class HostEntry(SpecificEtcdEntryBase):
|
|||
|
||||
def update_heartbeat(self):
|
||||
self.status = HostStatus.alive
|
||||
self.last_heartbeat = datetime.utcnow().isoformat()
|
||||
self.last_heartbeat = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
def is_alive(self):
|
||||
last_heartbeat = datetime.fromisoformat(self.last_heartbeat)
|
||||
delta = datetime.utcnow() - last_heartbeat
|
||||
|
||||
last_heartbeat = datetime.strptime(self.last_heartbeat, "%Y-%m-%d %H:%M:%S")
|
||||
delta = datetime.now() - last_heartbeat
|
||||
if delta.total_seconds() > 60:
|
||||
return False
|
||||
return True
|
||||
|
||||
def declare_dead(self):
|
||||
self.status = HostStatus.dead
|
||||
self.last_heartbeat = datetime.utcnow().isoformat()
|
||||
self.last_heartbeat = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
class HostPool:
|
||||
|
|
Loading…
Reference in a new issue