Skip to content

Commit e005c34

Browse files
macdiceCommitfest Bot
authored andcommitted
Rename poll-build job to poll-stale-build.
This name clarifies that it's only used when we think we might have missed webhooks because it has been a while or because of inconsistent state changes received by webhooks. Also allow jobs named poll- to be retried, since they make network requests that might be randomly flaky.
1 parent 55e8de5 commit e005c34

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

cfbot_cirrus.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def poll_stale_branch(conn, branch_id):
157157
build_status = build["status"]
158158
# if build_status not in FINAL_BUILD_STATUSES:
159159
cfbot_work_queue.insert_work_queue_if_not_exists(
160-
cursor, "poll-build", build_id
160+
cursor, "poll-stale-build", build_id
161161
)
162162

163163

@@ -188,8 +188,6 @@ def maybe_change_branch_status(cursor, build_id, build_status, commit_id):
188188
(branch_status, commit_id, commit_id, build_id),
189189
)
190190
for (branch_id,) in cursor.fetchall():
191-
# XXX could check if all tasks are in final state, and if not
192-
# enqueue poll-build for a final sync?
193191
logging.info("branch %s testing -> %s", branch_id, branch_status)
194192
cfbot_work_queue.insert_work_queue_if_not_exists(
195193
cursor, "post-branch-status", branch_id
@@ -231,7 +229,7 @@ def fetch_task_commands(conn, task_id):
231229
# https://cirrus-ci.org/api/#builds-and-tasks-webhooks
232230
#
233231
# Since webooks are unreliable, we check that the transition matches the
234-
# existing database state. If it doesn't, we enqueue a full poll-build job to
232+
# existing database state. If it doesn't, we enqueue a poll-stale-build job to
235233
# resynchonise.
236234
def ingest_webhook(conn, event_type, event):
237235
cursor = conn.cursor()
@@ -255,7 +253,7 @@ def ingest_webhook(conn, event_type, event):
255253
if cursor.rowcount == 0:
256254
logging.info("webhook out of sync: build %s already exists", build_id)
257255
cfbot_work_queue.insert_work_queue_if_not_exists(
258-
cursor, "poll-build", build_id
256+
cursor, "poll-stale-build", build_id
259257
)
260258
return
261259
logging.info("new build %s %s", build_id, build_status)
@@ -276,23 +274,28 @@ def ingest_webhook(conn, event_type, event):
276274
old_build_status,
277275
)
278276
cfbot_work_queue.insert_work_queue_if_not_exists(
279-
cursor, "poll-build", build_id
277+
cursor, "poll-stale-build", build_id
280278
)
281279
return
282280
logging.info("build %s %s -> %s", build_id, old_build_status, build_status)
283281
if build_status in FINAL_BUILD_STATUSES:
284-
cursor.execute("""SELECT COUNT(*)
282+
cursor.execute(
283+
"""SELECT COUNT(*)
285284
FROM task
286285
WHERE build_id = %s
287286
AND status NOT IN ('FAILED', 'ABORTED', 'ERRORED', 'COMPLETED', 'PAUSED')
288287
LIMIT 1""",
289-
(build_id,))
290-
running_tasks, = cursor.fetchone()
288+
(build_id,),
289+
)
290+
(running_tasks,) = cursor.fetchone()
291291
if running_tasks > 0:
292-
logging.info("webhook out of sync: build %s has final status but has %d tasks with non-final, non-PAUSED status",
293-
build_id, running_tasks)
292+
logging.info(
293+
"webhook out of sync: build %s has final status but has %d tasks with non-final, non-PAUSED status",
294+
build_id,
295+
running_tasks,
296+
)
294297
cfbot_work_queue.insert_work_queue_if_not_exists(
295-
cursor, "poll-build", build_id
298+
cursor, "poll-stale-build", build_id
296299
)
297300
maybe_change_branch_status(cursor, build_id, build_status, commit_id)
298301
elif event_type == "task":
@@ -314,7 +317,7 @@ def ingest_webhook(conn, event_type, event):
314317
"webhook out of sync: referenced build %s does not exist", build_id
315318
)
316319
cfbot_work_queue.insert_work_queue_if_not_exists(
317-
cursor, "poll-build", build_id
320+
cursor, "poll-stale-build", build_id
318321
)
319322
return
320323

@@ -347,7 +350,7 @@ def ingest_webhook(conn, event_type, event):
347350
if cursor.rowcount == 0:
348351
logging.info("webhook out of sync: task %s already exists", task_id)
349352
cfbot_work_queue.insert_work_queue_if_not_exists(
350-
cursor, "poll-build", build_id
353+
cursor, "poll-stale-build", build_id
351354
)
352355
return
353356
logging.info("new task %s %s", task_id, task_status)
@@ -368,7 +371,7 @@ def ingest_webhook(conn, event_type, event):
368371
old_task_status,
369372
)
370373
cfbot_work_queue.insert_work_queue_if_not_exists(
371-
cursor, "poll-build", build_id
374+
cursor, "poll-stale-build", build_id
372375
)
373376
return
374377
logging.info("task %s %s -> %s", task_id, old_task_status, task_status)
@@ -381,12 +384,12 @@ def ingest_webhook(conn, event_type, event):
381384
cfbot_work_queue.insert_work_queue(cursor, "fetch-task-commands", task_id)
382385

383386

384-
# Handler for "poll-build" jobs.
387+
# Handler for "poll-stale-build" jobs.
385388
#
386-
# These are created by the "poll-stale-branch" handler, used to poll branches
389+
# These are created by the "poll-stale-branch" handler, used to advance branches
387390
# that seem to be stuck. Note that it is careful to lock a build row so that it
388391
# can safely run concurrently with ingest_webhook().
389-
def poll_build(conn, build_id):
392+
def poll_stale_build(conn, build_id):
390393
cursor = conn.cursor()
391394

392395
# Serialise the API calls about this build by making sure we have a row to

cfbot_work_queue.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def highlight_patterns(cursor, task_id, source, patterns, line, types):
4141

4242

4343
def retry_limit(type):
44-
if type.startswith("fetch-") or type.startswith("post-"):
44+
if (
45+
type.startswith("fetch-")
46+
or type.startswith("poll-")
47+
or type.startswith("post-")
48+
):
4549
# Things that hit network APIs get multiple retries
4650
return 3
4751

@@ -545,12 +549,10 @@ def process_one_job(conn, fetch_only):
545549
analyze_task_tests(conn, key)
546550
elif type == "refresh-highlight-pages":
547551
refresh_highlight_pages(conn, key)
548-
elif type == "poll-stale-branches":
549-
cfbot_cirrus.poll_stale_branches(conn)
550552
elif type == "poll-stale-branch":
551553
cfbot_cirrus.poll_stale_branch(conn, key)
552-
elif type == "poll-build":
553-
cfbot_cirrus.poll_build(conn, key)
554+
elif type == "poll-stale-build":
555+
cfbot_cirrus.poll_stale_build(conn, key)
554556
elif type == "post-task-status":
555557
cfbot_commitfest.post_task_status(conn, key)
556558
elif type == "post-branch-status":

0 commit comments

Comments
 (0)