@@ -157,7 +157,7 @@ def poll_stale_branch(conn, branch_id):
157
157
build_status = build ["status" ]
158
158
# if build_status not in FINAL_BUILD_STATUSES:
159
159
cfbot_work_queue .insert_work_queue_if_not_exists (
160
- cursor , "poll-build" , build_id
160
+ cursor , "poll-stale- build" , build_id
161
161
)
162
162
163
163
@@ -188,8 +188,6 @@ def maybe_change_branch_status(cursor, build_id, build_status, commit_id):
188
188
(branch_status , commit_id , commit_id , build_id ),
189
189
)
190
190
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?
193
191
logging .info ("branch %s testing -> %s" , branch_id , branch_status )
194
192
cfbot_work_queue .insert_work_queue_if_not_exists (
195
193
cursor , "post-branch-status" , branch_id
@@ -231,7 +229,7 @@ def fetch_task_commands(conn, task_id):
231
229
# https://cirrus-ci.org/api/#builds-and-tasks-webhooks
232
230
#
233
231
# 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
235
233
# resynchonise.
236
234
def ingest_webhook (conn , event_type , event ):
237
235
cursor = conn .cursor ()
@@ -255,7 +253,7 @@ def ingest_webhook(conn, event_type, event):
255
253
if cursor .rowcount == 0 :
256
254
logging .info ("webhook out of sync: build %s already exists" , build_id )
257
255
cfbot_work_queue .insert_work_queue_if_not_exists (
258
- cursor , "poll-build" , build_id
256
+ cursor , "poll-stale- build" , build_id
259
257
)
260
258
return
261
259
logging .info ("new build %s %s" , build_id , build_status )
@@ -276,23 +274,28 @@ def ingest_webhook(conn, event_type, event):
276
274
old_build_status ,
277
275
)
278
276
cfbot_work_queue .insert_work_queue_if_not_exists (
279
- cursor , "poll-build" , build_id
277
+ cursor , "poll-stale- build" , build_id
280
278
)
281
279
return
282
280
logging .info ("build %s %s -> %s" , build_id , old_build_status , build_status )
283
281
if build_status in FINAL_BUILD_STATUSES :
284
- cursor .execute ("""SELECT COUNT(*)
282
+ cursor .execute (
283
+ """SELECT COUNT(*)
285
284
FROM task
286
285
WHERE build_id = %s
287
286
AND status NOT IN ('FAILED', 'ABORTED', 'ERRORED', 'COMPLETED', 'PAUSED')
288
287
LIMIT 1""" ,
289
- (build_id ,))
290
- running_tasks , = cursor .fetchone ()
288
+ (build_id ,),
289
+ )
290
+ (running_tasks ,) = cursor .fetchone ()
291
291
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
+ )
294
297
cfbot_work_queue .insert_work_queue_if_not_exists (
295
- cursor , "poll-build" , build_id
298
+ cursor , "poll-stale- build" , build_id
296
299
)
297
300
maybe_change_branch_status (cursor , build_id , build_status , commit_id )
298
301
elif event_type == "task" :
@@ -314,7 +317,7 @@ def ingest_webhook(conn, event_type, event):
314
317
"webhook out of sync: referenced build %s does not exist" , build_id
315
318
)
316
319
cfbot_work_queue .insert_work_queue_if_not_exists (
317
- cursor , "poll-build" , build_id
320
+ cursor , "poll-stale- build" , build_id
318
321
)
319
322
return
320
323
@@ -347,7 +350,7 @@ def ingest_webhook(conn, event_type, event):
347
350
if cursor .rowcount == 0 :
348
351
logging .info ("webhook out of sync: task %s already exists" , task_id )
349
352
cfbot_work_queue .insert_work_queue_if_not_exists (
350
- cursor , "poll-build" , build_id
353
+ cursor , "poll-stale- build" , build_id
351
354
)
352
355
return
353
356
logging .info ("new task %s %s" , task_id , task_status )
@@ -368,7 +371,7 @@ def ingest_webhook(conn, event_type, event):
368
371
old_task_status ,
369
372
)
370
373
cfbot_work_queue .insert_work_queue_if_not_exists (
371
- cursor , "poll-build" , build_id
374
+ cursor , "poll-stale- build" , build_id
372
375
)
373
376
return
374
377
logging .info ("task %s %s -> %s" , task_id , old_task_status , task_status )
@@ -381,12 +384,12 @@ def ingest_webhook(conn, event_type, event):
381
384
cfbot_work_queue .insert_work_queue (cursor , "fetch-task-commands" , task_id )
382
385
383
386
384
- # Handler for "poll-build" jobs.
387
+ # Handler for "poll-stale- build" jobs.
385
388
#
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
387
390
# that seem to be stuck. Note that it is careful to lock a build row so that it
388
391
# can safely run concurrently with ingest_webhook().
389
- def poll_build (conn , build_id ):
392
+ def poll_stale_build (conn , build_id ):
390
393
cursor = conn .cursor ()
391
394
392
395
# Serialise the API calls about this build by making sure we have a row to
0 commit comments