Skip to content

Commit 1d3ed53

Browse files
Revert "Filter running jobs by project event instead of commit SHA (#3027)" (#3037)
Revert "Filter running jobs by project event instead of commit SHA (#3027)" This reverts commit 641e663 Reviewed-by: Nikola Forró Reviewed-by: gemini-code-assist[bot]
2 parents cf4018e + 5eb12a9 commit 1d3ed53

File tree

4 files changed

+36
-90
lines changed

4 files changed

+36
-90
lines changed

packit_service/models.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,20 +2176,15 @@ def get_by_id(cls, group_id: int) -> Optional["CoprBuildGroupModel"]:
21762176
return session.query(CoprBuildGroupModel).filter_by(id=group_id).first()
21772177

21782178
@classmethod
2179-
def get_running(
2180-
cls,
2181-
project_event_type: ProjectEventModelType,
2182-
event_id: int,
2183-
) -> Iterable[tuple["CoprBuildTargetModel"]]:
2184-
"""Get list of currently running Copr builds for a given project object
2185-
(e.g. a PR or branch).
2179+
def get_running(cls, commit_sha: str) -> Iterable[tuple["CoprBuildTargetModel"]]:
2180+
"""Get list of currently running Copr builds matching the passed
2181+
arguments.
21862182
21872183
Args:
2188-
project_event_type: Type of the project event (e.g. pull_request).
2189-
event_id: ID of the project object (e.g. PullRequestModel.id).
2184+
commit_sha: Commit hash that is used for filtering the running jobs.
21902185
21912186
Returns:
2192-
An iterable over Copr target models that are currently in queue
2187+
An iterable over Copr target models that are curently in queue
21932188
(running) or waiting for an SRPM.
21942189
"""
21952190
q = (
@@ -2198,8 +2193,7 @@ def get_running(
21982193
.join(PipelineModel)
21992194
.join(ProjectEventModel)
22002195
.filter(
2201-
ProjectEventModel.type == project_event_type,
2202-
ProjectEventModel.event_id == event_id,
2196+
ProjectEventModel.commit_sha == commit_sha,
22032197
CoprBuildTargetModel.status.in_(
22042198
(BuildStatus.pending, BuildStatus.waiting_for_srpm)
22052199
),
@@ -3628,18 +3622,12 @@ def get_by_id(cls, group_id: int) -> Optional["TFTTestRunGroupModel"]:
36283622
return session.query(TFTTestRunGroupModel).filter_by(id=group_id).first()
36293623

36303624
@classmethod
3631-
def get_running(
3632-
cls,
3633-
project_event_type: ProjectEventModelType,
3634-
event_id: int,
3635-
ranch: str,
3636-
) -> Iterable[tuple["TFTTestRunTargetModel"]]:
3637-
"""Get list of currently running Testing Farm runs for a given project
3638-
object (e.g. a PR or branch).
3625+
def get_running(cls, commit_sha: str, ranch: str) -> Iterable[tuple["TFTTestRunTargetModel"]]:
3626+
"""Get list of currently running Testing Farm runs matching the passed
3627+
arguments.
36393628
36403629
Args:
3641-
project_event_type: Type of the project event (e.g. pull_request).
3642-
event_id: ID of the project object (e.g. PullRequestModel.id).
3630+
commit_sha: Commit hash that is used for filtering the running jobs.
36433631
ranch: Testing Farm ranch where the tests are supposed to be run.
36443632
36453633
Returns:
@@ -3653,8 +3641,7 @@ def get_running(
36533641
.join(PipelineModel)
36543642
.join(ProjectEventModel)
36553643
.filter(
3656-
ProjectEventModel.type == project_event_type,
3657-
ProjectEventModel.event_id == event_id,
3644+
ProjectEventModel.commit_sha == commit_sha,
36583645
TFTTestRunGroupModel.ranch == ranch,
36593646
TFTTestRunTargetModel.status.in_(
36603647
(
@@ -4945,17 +4932,12 @@ def get_by_id(cls, group_id: int) -> Optional["LogDetectiveRunGroupModel"]:
49454932
return session.query(LogDetectiveRunGroupModel).filter_by(id=group_id).first()
49464933

49474934
@classmethod
4948-
def get_running(
4949-
cls,
4950-
project_event_type: ProjectEventModelType,
4951-
event_id: int,
4952-
) -> Iterable[tuple[LogDetectiveRunModel]]:
4953-
"""Get list of currently running Log Detective runs for a given project
4954-
object (e.g. a PR or branch).
4935+
def get_running(cls, commit_sha: str) -> Iterable[tuple[LogDetectiveRunModel]]:
4936+
"""Get list of currently running Log Detective runs matching the passed
4937+
arguments.
49554938
49564939
Args:
4957-
project_event_type: Type of the project event (e.g. pull_request).
4958-
event_id: ID of the project object (e.g. PullRequestModel.id).
4940+
commit_sha: Commit hash that is used for filtering the running jobs.
49594941
49604942
Returns:
49614943
An iterable over Log Detective run models representing Log Detective runs
@@ -4967,8 +4949,7 @@ def get_running(
49674949
.join(PipelineModel)
49684950
.join(ProjectEventModel)
49694951
.filter(
4970-
ProjectEventModel.type == project_event_type,
4971-
ProjectEventModel.event_id == event_id,
4952+
ProjectEventModel.commit_sha == commit_sha,
49724953
LogDetectiveRunModel.status == LogDetectiveResult.running,
49734954
)
49744955
)

packit_service/worker/helpers/build/copr_build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,10 +1024,10 @@ def get_configured_targets(self) -> set[str]:
10241024
def get_running_jobs(
10251025
self,
10261026
) -> Union[Iterable[tuple["CoprBuildTargetModel"]], Iterable[tuple["TFTTestRunTargetModel"]]]:
1027-
yield from CoprBuildGroupModel.get_running(
1028-
project_event_type=self.db_project_event.type,
1029-
event_id=self.db_project_event.event_id,
1030-
)
1027+
if sha := self.metadata.commit_sha_before:
1028+
yield from CoprBuildGroupModel.get_running(commit_sha=sha)
1029+
1030+
# [SAFETY] When there's no previous commit hash, yields nothing
10311031

10321032
def cancel_running_builds(self):
10331033
running_builds = list(self.get_running_jobs())

packit_service/worker/helpers/testing_farm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,12 @@ def report_status_to_configured_job(
12341234
)
12351235

12361236
def get_running_jobs(self) -> Iterable[tuple["TFTTestRunTargetModel"]]:
1237-
yield from TFTTestRunGroupModel.get_running(
1238-
project_event_type=self.db_project_event.type,
1239-
event_id=self.db_project_event.event_id,
1240-
ranch=self.tft_client.default_ranch,
1241-
)
1237+
if sha := self.metadata.commit_sha_before:
1238+
yield from TFTTestRunGroupModel.get_running(
1239+
commit_sha=sha, ranch=self.tft_client.default_ranch
1240+
)
1241+
1242+
# [SAFETY] When there's no previous commit hash, yields nothing
12421243

12431244
def cancel_running_tests(self):
12441245
running_tests = list(self.get_running_jobs())

tests_openshift/database/test_models.py

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,12 +1274,7 @@ def test_create_koji_tag_request(clean_before_and_after, a_koji_tag_request):
12741274
assert a_koji_tag_request.get_project().project_url == SampleValues.project_url
12751275

12761276

1277-
def test_copr_get_running(
1278-
clean_before_and_after,
1279-
pr_model,
1280-
pr_project_event_model,
1281-
srpm_build_model_with_new_run_for_pr,
1282-
):
1277+
def test_copr_get_running(clean_before_and_after, pr_model, srpm_build_model_with_new_run_for_pr):
12831278
_, run_model = srpm_build_model_with_new_run_for_pr
12841279
group, _ = CoprBuildGroupModel.create(run_model=run_model)
12851280

@@ -1299,25 +1294,15 @@ def test_copr_get_running(
12991294
copr_build_group=group,
13001295
)
13011296

1302-
running = list(
1303-
CoprBuildGroupModel.get_running(
1304-
project_event_type=pr_project_event_model.type,
1305-
event_id=pr_project_event_model.event_id,
1306-
)
1307-
)
1297+
running = list(CoprBuildGroupModel.get_running(commit_sha=SampleValues.commit_sha))
13081298
assert running, "There are some running builds present"
13091299
assert len(running) == 3, "There are exactly 3 builds running"
13101300
assert {build.build_id for (build,) in running} == {"1", "2"}, (
13111301
"Exactly ‹1› and ‹2› are in the running state"
13121302
)
13131303

13141304

1315-
def test_tmt_get_running(
1316-
clean_before_and_after,
1317-
pr_model,
1318-
pr_project_event_model,
1319-
srpm_build_model_with_new_run_for_pr,
1320-
):
1305+
def test_tmt_get_running(clean_before_and_after, pr_model, srpm_build_model_with_new_run_for_pr):
13211306
_, run_model = srpm_build_model_with_new_run_for_pr
13221307
group = TFTTestRunGroupModel.create(run_model, ranch="public")
13231308

@@ -1335,11 +1320,7 @@ def test_tmt_get_running(
13351320
)
13361321

13371322
running = list(
1338-
TFTTestRunGroupModel.get_running(
1339-
project_event_type=pr_project_event_model.type,
1340-
event_id=pr_project_event_model.event_id,
1341-
ranch="public",
1342-
)
1323+
TFTTestRunGroupModel.get_running(commit_sha=SampleValues.commit_sha, ranch="public")
13431324
)
13441325
assert running, "There are some running tests present"
13451326
assert len(running) == 2, "There are exactly 2 tests running"
@@ -1349,10 +1330,7 @@ def test_tmt_get_running(
13491330

13501331

13511332
def test_tmt_get_running_different_ranches(
1352-
clean_before_and_after,
1353-
pr_model,
1354-
pr_project_event_model,
1355-
srpm_build_model_with_new_run_for_pr,
1333+
clean_before_and_after, pr_model, srpm_build_model_with_new_run_for_pr
13561334
):
13571335
_, run_model = srpm_build_model_with_new_run_for_pr
13581336

@@ -1381,11 +1359,7 @@ def test_tmt_get_running_different_ranches(
13811359
)
13821360

13831361
running = list(
1384-
TFTTestRunGroupModel.get_running(
1385-
project_event_type=pr_project_event_model.type,
1386-
event_id=pr_project_event_model.event_id,
1387-
ranch="public",
1388-
)
1362+
TFTTestRunGroupModel.get_running(commit_sha=SampleValues.commit_sha, ranch="public")
13891363
)
13901364
assert running, "There are some running tests present"
13911365
assert len(running) == 2, "There are exactly 2 tests running in the public ranch"
@@ -1394,11 +1368,7 @@ def test_tmt_get_running_different_ranches(
13941368
)
13951369

13961370
running = list(
1397-
TFTTestRunGroupModel.get_running(
1398-
project_event_type=pr_project_event_model.type,
1399-
event_id=pr_project_event_model.event_id,
1400-
ranch="redhat",
1401-
)
1371+
TFTTestRunGroupModel.get_running(commit_sha=SampleValues.commit_sha, ranch="redhat")
14021372
)
14031373
assert running, "There are some running tests present"
14041374
assert len(running) == 2, "There are exactly 2 tests running in the redhat ranch"
@@ -1538,9 +1508,7 @@ def test_log_detective_run_group_targets(
15381508
assert group.grouped_targets[0] == run_target
15391509

15401510

1541-
def test_log_detective_get_running(
1542-
clean_before_and_after, pr_project_event_model, srpm_build_model_with_new_run_for_pr
1543-
):
1511+
def test_log_detective_get_running(clean_before_and_after, srpm_build_model_with_new_run_for_pr):
15441512
_, run_model = srpm_build_model_with_new_run_for_pr
15451513
group = LogDetectiveRunGroupModel.create([run_model])
15461514

@@ -1574,12 +1542,8 @@ def test_log_detective_get_running(
15741542
target="",
15751543
)
15761544

1577-
running = list(
1578-
LogDetectiveRunGroupModel.get_running(
1579-
project_event_type=pr_project_event_model.type,
1580-
event_id=pr_project_event_model.event_id,
1581-
)
1582-
)
1545+
# The fixture uses SampleValues.commit_sha ("80201a74d96c")
1546+
running = list(LogDetectiveRunGroupModel.get_running(SampleValues.commit_sha))
15831547

15841548
assert running, "There should be running analysis present"
15851549
assert len(running) == 1, "There is exactly 1 analysis running"

0 commit comments

Comments
 (0)