Skip to content

Commit ad8e40d

Browse files
authored
Merge pull request #22446 from mvdbeek/fix-scheduling-delay
[25.1] Use correct timezone to compare step scheduling
2 parents 84506e3 + 5962ba2 commit ad8e40d

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
@@ -12,6 +12,7 @@
1212
from galaxy import model
1313
from galaxy.exceptions import HandlerAssignmentError
1414
from galaxy.jobs.handler import InvocationGrabber
15+
from galaxy.model.orm.now import now
1516
from galaxy.schema.invocation import (
1617
FailureReason,
1718
InvocationFailureDatasetFailed,
@@ -341,12 +342,12 @@ def ready_to_schedule_more(self, invocation: model.WorkflowInvocation):
341342
invocation_step_update_time := invocation.get_last_workflow_invocation_step_update_time()
342343
):
343344
do_schedule = invocation_step_update_time > last_schedule_time
344-
if not do_schedule and (datetime.now() - last_schedule_time) > self.timedelta:
345+
if not do_schedule and (now() - last_schedule_time) > self.timedelta:
345346
# If we haven't scheduled in a while, schedule anyway.
346347
log.debug(
347348
"Scheduling workflow invocation [%s] after %s seconds without scheduling.",
348349
invocation.id,
349-
(datetime.now() - last_schedule_time).total_seconds(),
350+
(now() - last_schedule_time).total_seconds(),
350351
)
351352
do_schedule = True
352353
return do_schedule
@@ -449,7 +450,7 @@ def __attempt_schedule(self, invocation_id, workflow_scheduler):
449450
if i.active and i.id < workflow_invocation.id:
450451
return False
451452
if self.ready_to_schedule_more(workflow_invocation):
452-
self.update_time_tracking_dict[invocation_id] = datetime.now()
453+
self.update_time_tracking_dict[invocation_id] = now()
453454
workflow_scheduler.schedule(workflow_invocation)
454455
log.debug("Workflow invocation [%s] scheduled", invocation_id)
455456
except Exception:

0 commit comments

Comments
 (0)