Skip to content

Commit

Permalink
Unset srpm url if all tasks have failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwaizer committed Oct 27, 2024
1 parent 350f851 commit 60f9ee3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions alws/crud/build_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ def get_srpm_instance(
# SourceRpm and BinaryRpm records, because it breaks package releases
if status in (BuildTaskStatus.EXCLUDED, BuildTaskStatus.FAILED):
continue

if rpm.name.endswith(".src.rpm") and srpm is None:
srpm = models.SourceRpm()
srpm.artifact = rpm
Expand Down
49 changes: 36 additions & 13 deletions alws/dramatiq/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ async def _start_build(build_id: int, build_request: build_schema.BuildCreate):

async def _build_done(request: build_node_schema.BuildDone):
async with open_async_session(key=get_async_db_key()) as db:
build_task = (
(
await db.execute(
select(models.BuildTask).where(
models.BuildTask.id == request.task_id
)
)
)
.scalars()
.first()
)
try:
await build_node_crud.safe_build_done(db, request)
except Exception as e:
Expand All @@ -166,23 +177,23 @@ async def _build_done(request: build_node_schema.BuildDone):
request.task_id,
str(e),
)
build_task = (
(
await db.execute(
select(models.BuildTask).where(
models.BuildTask.id == request.task_id
)
)
)
.scalars()
.first()
)
build_task.ts = datetime.datetime.utcnow()
build_task.error = str(e)
build_task.status = BuildTaskStatus.FAILED
await build_node_crud.fast_fail_other_tasks_by_ref(db, build_task)
await db.flush()

build_id = build_task.id

# We need to unset srpm_url if all tasks failed
build_tasks = (await db.execute(
select(models.BuildTask).where(
models.BuildTask.build_id == build_id,
models.BuildTask.ref_id == build_task.ref_id,
models.BuildTask.arch != 'src',
)
)).scalars().all()

# We don't want to create the test tasks until all build tasks
# of the same build_id are completed.
# The last completed task will trigger the creation of the test tasks
Expand All @@ -192,7 +203,18 @@ async def _build_done(request: build_node_schema.BuildDone):
)

if all_build_tasks_completed:
build_id = await _get_build_id(db, request.task_id)
failed_tasks = [task for task in build_tasks if task.status == BuildTaskStatus.FAILED]
if len(failed_tasks) == len(build_tasks):
await db.execute(
update(models.BuildTask).where(
models.BuildTask.build_id == build_id,
models.BuildTask.ref_id == build_task.ref_id,
).values(
status=BuildTaskStatus.FAILED,
built_srpm_url=None,
)
)

cancel_testing = (
await db.execute(
select(models.Build.cancel_testing).where(
Expand All @@ -209,13 +231,14 @@ async def _build_done(request: build_node_schema.BuildDone):
build_id,
str(e),
)
build_id = await _get_build_id(db, request.task_id)
await db.execute(
update(models.Build)
.where(models.Build.id == build_id)
.values(finished_at=datetime.datetime.utcnow())
)

await db.flush()


async def _get_build_id(db: AsyncSession, build_task_id: int) -> int:
build_id = (
Expand Down

0 comments on commit 60f9ee3

Please sign in to comment.