Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packit_service/worker/handlers/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging
import os
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
from typing import Optional

from celery import Task, signature
Expand Down Expand Up @@ -477,15 +477,17 @@ def handle_testing_farm(self):

event_dict = self.data.get_dict()

if (
self.build
and self.build.group_of_targets.runs
and (cutoff := self.build.group_of_targets.runs[0].datetime)
):
# use the pipeline datetime of the current build rather than
# recomputing via `get_latest_datetime_for_event()`, to avoid
# canceling tests triggered by sibling builds from the same batch
event_dict["cancel_cutoff_time"] = cutoff.timestamp()
if self.build and self.build.group_of_targets.runs:
# find the earliest pipeline datetime in the current build batch;
# using a cutoff just before it ensures we only cancel tests from
# previous batches, not sibling tests from the same batch that
# were submitted on earlier pipelines
earliest = min(
(run.datetime for run in self.build.group_of_targets.runs if run.datetime),
default=None,
)
if earliest:
event_dict["cancel_cutoff_time"] = (earliest - timedelta(seconds=1)).timestamp()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PipelineModel.datetime column stores naive datetime objects representing UTC. When calling .timestamp() on a naive datetime object, Python assumes it is in the local system timezone. If the server environment is not configured to UTC, this will result in an incorrect timestamp offset. It is safer to explicitly set the timezone to UTC before calculating the timestamp.

Suggested change
event_dict["cancel_cutoff_time"] = (earliest - timedelta(seconds=1)).timestamp()
event_dict["cancel_cutoff_time"] = (
earliest.replace(tzinfo=timezone.utc) - timedelta(seconds=1)
).timestamp()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this matters here.


for job_config in self.copr_build_helper.job_tests_all:
if (
Expand Down
Loading