From 9f229eae27f9007e9c6c1021d3d5b12452863763 Mon Sep 17 00:00:00 2001 From: meow Date: Wed, 23 Oct 2019 17:28:42 +0500 Subject: [PATCH] a --- LICENSE | 0 Pipfile.lock | 0 setup.py | 0 ucloud_common/host.py | 11 +++++++---- 4 files changed, 7 insertions(+), 4 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 Pipfile.lock mode change 100644 => 100755 setup.py diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Pipfile.lock b/Pipfile.lock old mode 100644 new mode 100755 diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 diff --git a/ucloud_common/host.py b/ucloud_common/host.py index d620e4b..189354b 100755 --- a/ucloud_common/host.py +++ b/ucloud_common/host.py @@ -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: