@@ -156,15 +156,14 @@ def add(
156
156
job dies.
157
157
can_start_at : datetime
158
158
The earliest time the task can be started.
159
- If None, set current time. A task will not be started before this
160
- time.
159
+ If None, set current time. For consistency the time is
160
+ from the database clock. A task will not be started before
161
+ this time.
161
162
Returns
162
163
-------
163
164
task_id :
164
165
The random UUID that was generated for this task
165
166
"""
166
- if can_start_at is None :
167
- can_start_at = datetime .now (UTC )
168
167
# make sure the timeout is an actual number, otherwise we'll run
169
168
# into problems later when we calculate the actual deadline
170
169
lease_timeout = float (lease_timeout )
@@ -186,7 +185,7 @@ def add(
186
185
lease_timeout,
187
186
can_start_at
188
187
)
189
- VALUES (%s, %s, %s, %s, %s, %s )
188
+ VALUES (%s, %s, %s, %s, %s, COALESCE(%s, current_timestamp) )
190
189
"""
191
190
).format (sql .Identifier (self ._table_name )),
192
191
(
@@ -222,16 +221,15 @@ def add_many(
222
221
job dies.
223
222
can_start_at : datetime
224
223
The earliest time the task can be started.
225
- If None, set current time. A task will not be started before this
224
+ If None, set current time. For consistency the time is
225
+ from the database clock. A task will not be started before this
226
226
time.
227
227
Returns
228
228
-------
229
229
task_ids :
230
230
List of random UUIDs that were generated for this task.
231
231
The order is the same of the given tasks
232
232
"""
233
- if can_start_at is None :
234
- can_start_at = datetime .now (UTC )
235
233
# make sure the timeout is an actual number, otherwise we'll run
236
234
# into problems later when we calculate the actual deadline
237
235
lease_timeout = float (lease_timeout )
@@ -253,7 +251,9 @@ def add_many(
253
251
lease_timeout,
254
252
can_start_at
255
253
)
256
- VALUES (%s, %s, %s, %s, %s, %s)
254
+ VALUES (
255
+ %s, %s, %s, %s, %s, COALESCE(%s, current_timestamp)
256
+ )
257
257
"""
258
258
).format (sql .Identifier (self ._table_name )),
259
259
(
0 commit comments