3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-08-09 14:51:26 +00:00

Intertask cancellation via database

Task checking via database rated limited to once every 10s.
Rename killer.sby to cancelledby.sby and add Makefile for testing.
This commit is contained in:
Krystine Sherwin 2025-07-09 10:03:54 +12:00
parent e7c756a43f
commit 5fc8df43f8
No known key found for this signature in database
4 changed files with 49 additions and 6 deletions

View file

@ -17,6 +17,7 @@
#
import os, re, sys, signal, platform, click
import time
if os.name == "posix":
import resource, fcntl
import subprocess
@ -98,6 +99,7 @@ class SbyProc:
self.silent = silent
self.wait = False
self.job_lease = None
self.next_db = 0.0
self.task.update_proc_pending(self)
@ -183,6 +185,29 @@ class SbyProc:
self.task.cancel()
return
if time.time() >= self.next_db:
tasks_status = self.task.status_db.all_tasks_status()
for task_status in tasks_status.values():
if (task_status["status"] in ["PASS", "FAIL", "CANCELLED"] and
task_status["name"] in self.task.cancelledby):
if not self.silent:
status_time = time.localtime(task_status["status_created"])
if status_time.tm_yday == time.localtime().tm_yday:
# same day, format time only
time_format = r"%H:%M:%S"
else:
time_format = r"%x %H:%M:%S"
self.task.log(
f'Cancelled by {task_status["name"]!r} task '
f'with status {task_status["status"]!r} '
f'at {time.strftime(time_format, status_time)} '
'(consider calling sby with --statusreset if this seems wrong)'
)
self.task.cancel()
return
# don't hit the database every poll
self.next_db = time.time() + 10
if not self.running:
for dep in self.deps:
if not dep.finished:
@ -226,6 +251,10 @@ class SbyProc:
if self.job_lease:
self.job_lease.done()
if self.terminated:
# task already terminated, do not finish
return
if not self.silent:
self.task.log(f"{click.style(self.info, fg='magenta')}: finished (returncode={self.p.returncode})")