Skip to content

Commit

Permalink
always use DB clock when adding a task
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourour Benzarti committed Jul 24, 2024
1 parent 0b08e21 commit e405ce5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions postgrestq/task_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)),
(
Expand Down Expand Up @@ -222,16 +221,15 @@ 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
-------
task_ids :
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)
Expand All @@ -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)),
(
Expand Down

0 comments on commit e405ce5

Please sign in to comment.