From e405ce59a4e35649421d17688260e6b97d318284 Mon Sep 17 00:00:00 2001 From: Sourour Benzarti Date: Wed, 24 Jul 2024 15:28:15 +0200 Subject: [PATCH] always use DB clock when adding a task --- postgrestq/task_queue.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/postgrestq/task_queue.py b/postgrestq/task_queue.py index a45130a..8e54e97 100644 --- a/postgrestq/task_queue.py +++ b/postgrestq/task_queue.py @@ -156,15 +156,14 @@ def add( job dies. can_start_at : datetime The earliest time the task can be started. - If None, set current time. A task will not be started before this - time. + If None, set current time. For consistency the time is + from the database clock. A task will not be started before + this time. Returns ------- task_id : The random UUID that was generated for this task """ - if can_start_at is None: - can_start_at = datetime.now(UTC) # make sure the timeout is an actual number, otherwise we'll run # into problems later when we calculate the actual deadline lease_timeout = float(lease_timeout) @@ -186,7 +185,7 @@ def add( lease_timeout, can_start_at ) - VALUES (%s, %s, %s, %s, %s, %s) + VALUES (%s, %s, %s, %s, %s, COALESCE(%s, current_timestamp)) """ ).format(sql.Identifier(self._table_name)), ( @@ -222,7 +221,8 @@ def add_many( job dies. can_start_at : datetime The earliest time the task can be started. - If None, set current time. A task will not be started before this + If None, set current time. For consistency the time is + from the database clock. A task will not be started before this time. Returns ------- @@ -230,8 +230,6 @@ def add_many( List of random UUIDs that were generated for this task. The order is the same of the given tasks """ - if can_start_at is None: - can_start_at = datetime.now(UTC) # make sure the timeout is an actual number, otherwise we'll run # into problems later when we calculate the actual deadline lease_timeout = float(lease_timeout) @@ -253,7 +251,9 @@ def add_many( lease_timeout, can_start_at ) - VALUES (%s, %s, %s, %s, %s, %s) + VALUES ( + %s, %s, %s, %s, %s, COALESCE(%s, current_timestamp) + ) """ ).format(sql.Identifier(self._table_name)), (