Skip to content

Commit a87c19a

Browse files
committed
Attempt to compute a stable sort order for tasks.
I don't know if this will work... let's see.
1 parent 8ee182f commit a87c19a

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

cfbot_github.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def ingest_build(conn, build_id, commit_id, branch_name, build_status, source):
397397
update_branch(cursor, build_id, build_status, commit_id, branch_name)
398398

399399

400-
def ingest_task(conn, build_id, task_id, task_status, task_name, position, source):
400+
def ingest_task(conn, build_id, task_id, task_status, task_name, source):
401401
repo, run_id, run_attempt = split_build_id(build_id)
402402
repo, job_id = split_task_id(task_id)
403403
task_html_url = (
@@ -417,6 +417,30 @@ def ingest_task(conn, build_id, task_id, task_status, task_name, position, sourc
417417
cursor, "poll-github-run", build_id
418418
)
419419
return
420+
421+
# XXX Attempt to create a stable sort order. I don't know if this
422+
# strategy will actually work... it would be nice to be able to
423+
# use the order of jobs declared in the .yml file, without parsing
424+
# it... let's see if job_id is allocated sequentially and with
425+
# suitable control flow...
426+
cursor.execute(
427+
"""SELECT task_id, position
428+
FROM task
429+
WHERE build_id = %s
430+
LIMIT 1""",
431+
(build_id,),
432+
)
433+
if row := cursor.fetchone():
434+
# Compute relative ordering assuming that job IDs are assigned
435+
# sequentially. We can't use the job ID directly as they are
436+
# too big for int!
437+
reference_task_id, reference_position = row
438+
_, reference_job_id = split_task_id(reference_task_id)
439+
position = int(job_id) - int(reference_job_id)
440+
else:
441+
# The first job we hear about is given position 0
442+
position = 0
443+
420444
cursor.execute(
421445
"""INSERT INTO task (task_id,
422446
build_id,
@@ -489,15 +513,13 @@ def poll_workflow_run(conn, repo, run_id, run_attempt):
489513
jobs = get_github_api(
490514
repo, "runs/" + run_id + "/attempts/" + run_attempt + "/jobs"
491515
)["jobs"]
492-
position = 0
493516
for job in jobs:
494517
task_id = make_task_id(repo, job["id"])
495518
task_name = job["name"]
496519
task_status = convert_github_status_and_conclusion(
497520
job["status"], job["conclusion"]
498521
)
499-
position += 1
500-
ingest_task(conn, build_id, task_id, task_status, task_name, position, "poll")
522+
ingest_task(conn, build_id, task_id, task_status, task_name, "poll")
501523

502524

503525
# Find out about all runs associated with a repo + commit ID.
@@ -775,8 +797,7 @@ def ingest_workflow_job(conn, event):
775797
status = event["workflow_job"]["status"]
776798
conclusion = event["workflow_job"]["conclusion"]
777799
task_status = convert_github_status_and_conclusion(status, conclusion)
778-
position = 0 # ???
779-
ingest_task(conn, build_id, task_id, task_status, task_name, position, "webhook")
800+
ingest_task(conn, build_id, task_id, task_status, task_name, "webhook")
780801

781802

782803
# ======================================================================

0 commit comments

Comments
 (0)