Commit 998f175c32305f90f8d26c2fc6a517765ec130c6
1 parent
260c0356
Exists in
dev
fix datetime.utcnow
Showing
1 changed file
with
6 additions
and
6 deletions
Show diff stats
src/core/pyros_django/common/models.py
... | ... | @@ -714,7 +714,7 @@ class AgentCmd(models.Model): |
714 | 714 | |
715 | 715 | @classmethod |
716 | 716 | def max_deposit_date_for_peremption(cls): |
717 | - return datetime.utcnow() - timedelta(seconds=cls.DEFAULT_VALIDITY_DURATION) | |
717 | + return datetime.now(tz=timezone.utc) - timedelta(seconds=cls.DEFAULT_VALIDITY_DURATION) | |
718 | 718 | #return datetime.utcnow().astimezone() - timedelta(seconds=cls.DEFAULT_VALIDITY_DURATION) |
719 | 719 | #return datetime.utcnow().astimezone() - timedelta(hours=cls.DEFAULT_VALIDITY_DURATION) |
720 | 720 | |
... | ... | @@ -747,7 +747,7 @@ class AgentCmd(models.Model): |
747 | 747 | """ |
748 | 748 | printd("Delete all pending command(s) if exists (except very recent ones):") |
749 | 749 | #now_minus_2sec = datetime.utcnow().astimezone() - timedelta(seconds=2) |
750 | - now_minus_2sec = datetime.utcnow() - timedelta(seconds=2) | |
750 | + now_minus_2sec = datetime.now(tz=timezone.utc) - timedelta(seconds=2) | |
751 | 751 | #print("now_minus_2sec", now_minus_2sec) |
752 | 752 | pending_commands = cls.objects.filter( |
753 | 753 | # only commands for agent agent_name |
... | ... | @@ -969,7 +969,7 @@ class AgentCmd(models.Model): |
969 | 969 | if self.is_running(): return False |
970 | 970 | # return (datetime.utcnow() - self.s_deposit_time) > timedelta(seconds = self.validity_duration) |
971 | 971 | #elapsed_time = (datetime.utcnow().astimezone() - self.s_deposit_time) |
972 | - elapsed_time = ( datetime.utcnow() - self.s_deposit_time ) | |
972 | + elapsed_time = ( datetime.now(tz=timezone.utc) - self.s_deposit_time ) | |
973 | 973 | printd("elapsed_time", elapsed_time) |
974 | 974 | return elapsed_time > timedelta(seconds=self.validity_duration) |
975 | 975 | """ |
... | ... | @@ -998,7 +998,7 @@ class AgentCmd(models.Model): |
998 | 998 | if not self.is_running(): return False |
999 | 999 | # return (datetime.utcnow() - self.s_deposit_time) > timedelta(seconds = self.validity_duration) |
1000 | 1000 | #elapsed_time = (datetime.utcnow().astimezone() - self.r_start_time) |
1001 | - elapsed_time = (datetime.utcnow() - self.r_start_time) | |
1001 | + elapsed_time = (datetime.now(tz=timezone.utc) - self.r_start_time) | |
1002 | 1002 | printd("elapsed_time since exec", elapsed_time) |
1003 | 1003 | return elapsed_time > timedelta(seconds=self.exec_timeout) |
1004 | 1004 | # finished with any execution issue |
... | ... | @@ -1032,7 +1032,7 @@ class AgentCmd(models.Model): |
1032 | 1032 | |
1033 | 1033 | def set_read_time(self, do_save:bool=True): |
1034 | 1034 | #self.r_read_time = datetime.utcnow().astimezone() |
1035 | - self.r_read_time = datetime.utcnow() | |
1035 | + self.r_read_time = datetime.now(tz=timezone.utc) | |
1036 | 1036 | # Optimization: update only 1 field |
1037 | 1037 | if do_save: self.save(update_fields=["r_read_time"]) |
1038 | 1038 | |
... | ... | @@ -1102,7 +1102,7 @@ class AgentCmd(models.Model): |
1102 | 1102 | If result is present it will be set in the "result" field |
1103 | 1103 | ''' |
1104 | 1104 | #now_time = datetime.utcnow().astimezone() |
1105 | - now_time = datetime.utcnow() | |
1105 | + now_time = datetime.now(tz=timezone.utc) | |
1106 | 1106 | |
1107 | 1107 | if result: |
1108 | 1108 | self.set_result(result, False) | ... | ... |