Skip to content

Commit ee2550b

Browse files
committed
Use correct timezone to compare step scheduling
`get_last_workflow_invocation_step_update_time()` returns UTC time (it's set by galaxy.model.orm.now.now()) while datetime.now() is your local time. If your system is not on UTC time this caused 5 minute scheduling delays for steps depending on expression tools that only produce parameters. Fixes the delay observed in galaxyproject/tools-iuc#7314
1 parent d0edb08 commit ee2550b

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

lib/galaxy/model/orm/now.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from datetime import datetime
1+
from datetime import (
2+
datetime,
3+
timezone,
4+
)
25

36
# NOTE REGARDING TIMESTAMPS:
47
# It is currently difficult to have the timestamps calculated by the
@@ -7,7 +10,12 @@
710
# relies on the client's clock being set correctly, so if clustering
811
# web servers, use a time server to ensure synchronization
912

10-
# Return the current time in UTC without any timezone information
11-
now = datetime.utcnow
13+
14+
def now():
15+
"""
16+
Return the current time in UTC without any timezone information.
17+
"""
18+
return datetime.now(timezone.utc).replace(tzinfo=None)
19+
1220

1321
__all__ = ("now",)

lib/galaxy/workflow/scheduling_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from galaxy.exceptions import HandlerAssignmentError
1818
from galaxy.jobs.handler import InvocationGrabber
1919
from galaxy.model.base import check_database_connection
20+
from galaxy.model.orm.now import now
2021
from galaxy.schema.invocation import (
2122
FailureReason,
2223
InvocationFailureDatasetFailed,
@@ -350,12 +351,12 @@ def ready_to_schedule_more(self, invocation: model.WorkflowInvocation):
350351
invocation_step_update_time := invocation.get_last_workflow_invocation_step_update_time()
351352
):
352353
do_schedule = invocation_step_update_time > last_schedule_time
353-
if not do_schedule and (datetime.now() - last_schedule_time) > self.timedelta:
354+
if not do_schedule and (now() - last_schedule_time) > self.timedelta:
354355
# If we haven't scheduled in a while, schedule anyway.
355356
log.debug(
356357
"Scheduling workflow invocation [%s] after %s seconds without scheduling.",
357358
invocation.id,
358-
(datetime.now() - last_schedule_time).total_seconds(),
359+
(now() - last_schedule_time).total_seconds(),
359360
)
360361
do_schedule = True
361362
return do_schedule
@@ -459,7 +460,7 @@ def __attempt_schedule(self, invocation_id, workflow_scheduler):
459460
if i.active and i.id < workflow_invocation.id:
460461
return False
461462
if self.ready_to_schedule_more(workflow_invocation):
462-
self.update_time_tracking_dict[invocation_id] = datetime.now()
463+
self.update_time_tracking_dict[invocation_id] = now()
463464
workflow_scheduler.schedule(workflow_invocation)
464465
log.debug("Workflow invocation [%s] scheduled", invocation_id)
465466
except Exception:

0 commit comments

Comments
 (0)