Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions packit_service/events/koji/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class KojiEvent(Result):
def __init__(
self,
task_id: int,
parent: Optional[int] = None,
rpm_build_task_ids: Optional[dict[str, int]] = None,
start_time: Optional[Union[int, float, str]] = None,
completion_time: Optional[Union[int, float, str]] = None,
):
super().__init__()
self.task_id = task_id
self.parent = parent
# dictionary with archs and IDs, e.g. {"x86_64": 123}
self.rpm_build_task_ids = rpm_build_task_ids
self.start_time: Optional[Union[int, float, str]] = start_time
Expand Down
2 changes: 2 additions & 0 deletions packit_service/events/koji/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ def __init__(
self,
task_id: int,
state: KojiTaskState,
parent: Optional[int] = None,

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.

high

The parent parameter is added to Task.__init__, but it is currently missing from Task.from_event_dict() (around line 225). When Celery deserializes the event on the worker side, the parent attribute will be lost and default to None.\n\nPlease update Task.from_event_dict() to deserialize parent:\n\npython\n@classmethod\ndef from_event_dict(cls, event: dict) -> \"Task\":\n return Task(\n task_id=event.get(\"task_id\"),\n state=KojiTaskState(event.get(\"state\")) if event.get(\"state\") else None,\n parent=event.get(\"parent\"),\n ...\n )\n

old_state: Optional[KojiTaskState] = None,
rpm_build_task_ids: Optional[dict[str, int]] = None,
rpm_build_failed_arch_list: Optional[list[str]] = None,
start_time: Optional[Union[int, float, str]] = None,
completion_time: Optional[Union[int, float, str]] = None,
):
super().__init__(
parent=parent,
task_id=task_id,
rpm_build_task_ids=rpm_build_task_ids,
start_time=start_time,
Expand Down
12 changes: 12 additions & 0 deletions packit_service/worker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,18 @@ def parse_koji_task_event(event) -> Optional[koji.result.Task]:
start_time = nested_get(event, "info", "start_time")
completion_time = nested_get(event, "info", "completion_time")

# Check if it is an early update to an archbuild
if nested_get(event, "info", "method") == "buildArch":
parent = nested_get(event, "info", "parent")
return koji.result.Task(
parent=parent,
task_id=task_id,
state=state_enum,
old_state=old_state,
start_time=start_time,
completion_time=completion_time,
)
Comment on lines +1448 to +1457

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

To support reacting early to buildArch tasks for a specific architecture (as mentioned in your PR description's TODO), it would be highly beneficial to capture the architecture of the buildArch task from the event payload.\n\nYou can extract the architecture using nested_get(event, \"info\", \"arch\") and populate rpm_build_task_ids with {arch: task_id}. This avoids extra Koji API queries in the handlers.

Suggested change
if nested_get(event, "info", "method") == "buildArch":
parent = nested_get(event, "info", "parent")
return koji.result.Task(
parent=parent,
task_id=task_id,
state=state_enum,
old_state=old_state,
start_time=start_time,
completion_time=completion_time,
)
if nested_get(event, "info", "method") == "buildArch":
parent = nested_get(event, "info", "parent")
arch = nested_get(event, "info", "arch")
rpm_build_task_ids = {arch: task_id} if arch else {}
return koji.result.Task(
parent=parent,
task_id=task_id,
state=state_enum,
old_state=old_state,
start_time=start_time,
completion_time=completion_time,
rpm_build_task_ids=rpm_build_task_ids,
)


rpm_build_task_ids = {}
rpm_build_failed_arch_list: list[str] = []
for children in nested_get(event, "info", "children", default=[]):
Expand Down
Loading