Skip to content

Commit

Permalink
watch: fix naive datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamilcuk committed Aug 13, 2024
1 parent 413ad67 commit 1248ea5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/nomad_tools/entry_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def print_all_threads_stacktrace(*_):
out = "\n".join(x for x in "\n".join(text).splitlines() if x)
eprint("\n\n" + out + "\n\n")

def datetime_is_naive(d: datetime.datetime) -> bool:
return d.tzinfo is None or d.tzinfo.utcoffset(d) is None

###############################################################################

Expand Down Expand Up @@ -216,6 +218,7 @@ def __post_init__(self):
assert self.what in [
e.value for e in LogWhat
], f"{self.what} value is not a valid what"
assert not datetime_is_naive(self.now), f"{self}"

@property
def mark(self):
Expand Down Expand Up @@ -571,7 +574,7 @@ def log_deploy(cls, deploy: nomadlib.Deploy, message: str):
return cls.__log(
what=LogWhat.deploy,
id=deploy.ID,
now=ns2dt(job.SubmitTime) if job else datetime.datetime.now(),
now=ns2dt(job.SubmitTime) if job else datetime.datetime.now().astimezone(),
jobversion=deploy.JobVersion,
message=message,
ModifyIndex=deploy.ModifyIndex,
Expand Down Expand Up @@ -740,7 +743,7 @@ def run(self):
code = e.response.status_code if e.response is not None else None
text = e.response.text if e.response is not None else None
self.tk.log_alloc(
datetime.datetime.now(),
datetime.datetime.now().astimezone(),
f"Error getting {self.__typestr()} logs: {code} {text!r}",
)
finally:
Expand Down

0 comments on commit 1248ea5

Please sign in to comment.