Wire the pipeline scheduler in: models, finish hooks, admin

This commit is contained in:
claude authored and rektdie committed 2026-10-11 22:28:16 +02:00
1 parent 429b765657
commit d456f2fecf
5 files changed
+87

No files matched your search

+3
View File
@@ -27,3 +27,6 @@ django.contrib.admin.site.register(OpenBench.models.Result)
django.contrib.admin.site.register(OpenBench.models.Test)
django.contrib.admin.site.register(OpenBench.models.LogEvent)
django.contrib.admin.site.register(OpenBench.models.Network)
django.contrib.admin.site.register(OpenBench.models.Pipeline)
django.contrib.admin.site.register(OpenBench.models.PipelineRun)
django.contrib.admin.site.register(OpenBench.models.StepRun)
+68
View File
@@ -22,6 +22,9 @@ from django.db.models import CharField, IntegerField, BooleanField, FloatField
from django.db.models import JSONField, ForeignKey, DateTimeField, OneToOneField
from django.db.models import CASCADE, PROTECT, Model
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from OpenBench.pipeline_graph import validate_graph
class Engine(Model):
@@ -222,3 +225,68 @@ class PGN(Model):
def filename(self):
return '%s.%s.%s.pgn.bz2' % (self.test_id, self.result_id, self.book_index)
class Pipeline(Model):
# A reusable description of tests to run, and what to do with their outcomes.
# See OpenBench/pipeline_graph.py for what a graph looks like.
name = CharField(max_length=128)
author = CharField(max_length=64) # Username. Workloads created by the Pipeline belong to them
graph = JSONField(default=dict)
enabled = BooleanField(default=True) # Disabled Pipelines neither start, nor carry on
deleted = BooleanField(default=False)
created = DateTimeField(auto_now_add=True)
updated = DateTimeField(auto_now=True)
def __str__(self):
return '[%d] %s' % (self.id or 0, self.name)
def issues(self):
return validate_graph(self.graph)
def clean(self):
# Never save a Pipeline that could not run. Used by the Admin forms
errors = [i['message'] for i in self.issues() if i['level'] == 'error']
if errors:
raise ValidationError({ 'graph' : errors })
class PipelineRun(Model):
# One execution of a Pipeline. Works from a snapshot of the graph, so that
# editing a Pipeline never changes a run that is already underway.
pipeline = ForeignKey('Pipeline', CASCADE, related_name='runs')
graph = JSONField(default=dict)
starter = CharField(max_length=64)
status = CharField(max_length=16, default='RUNNING') # RUNNING, COMPLETED, ERROR, CANCELLED
fired = IntegerField(default=0) # Workloads created so far, to enforce max_steps
notes = JSONField(default=list, blank=True) # Why the run went the way it did
started = DateTimeField(auto_now_add=True)
updated = DateTimeField(auto_now=True)
def __str__(self):
return 'Run %d of Pipeline %d (%s)' % (self.id or 0, self.pipeline_id, self.status)
class StepRun(Model):
# One workload that a PipelineRun has created, or is about to create
#
# QUEUED -> LAUNCHING -> RUNNING -> PASSED | FAILED | STOPPED
# \-> ERROR ( the workload could not be created )
run = ForeignKey('PipelineRun', CASCADE, related_name='steps')
parent = ForeignKey('StepRun', CASCADE, null=True, blank=True, related_name='children')
step_key = CharField(max_length=32)
via = CharField(max_length=16, blank=True, default='') # Outcome of the parent that led here
kind = CharField(max_length=16)
payload = JSONField(default=dict) # Final form fields, after any overrides
status = CharField(max_length=16, default='QUEUED')
test_id = IntegerField(default=0, db_index=True) # 0 until the workload exists
message = CharField(max_length=512, blank=True, default='')
created = DateTimeField(auto_now_add=True)
updated = DateTimeField(auto_now=True)
resolved = DateTimeField(null=True, blank=True)
def __str__(self):
return '%s [%s] test=%d' % (self.step_key, self.status, self.test_id)
+10
View File
@@ -607,6 +607,12 @@ def network_edit(request, engine, network):
return OpenBench.views.redirect(request, '/networks/%s' % (network.engine), status='Applied changes')
def notify_pipelines(test_id):
# Imported late, since Pipelines create Workloads, which depend on this module
import OpenBench.pipelines
OpenBench.pipelines.workload_finished(test_id)
def update_test(request, machine):
# Extract error information
@@ -699,6 +705,10 @@ def update_test(request, machine):
if should_record_llr:
record_llr_history(test)
# Tell any Pipeline that cares, once the Workload is truly saved
if test.finished:
transaction.on_commit(lambda: notify_pipelines(test_id))
# Update Result object; No risk from concurrent access
Result.objects.filter(id=result_id).update(
games = F('games' ) + games,
+1
View File
@@ -824,6 +824,7 @@ def client_bench_error(request, machine):
# Find and stop the test with the bad bench
test = Test.objects.get(id=int(request.POST['test_id']))
test.finished = True; test.save()
OpenBench.utils.notify_pipelines(test.id)
# Log the error into the Events table
LogEvent.objects.create(
+5
View File
@@ -25,6 +25,7 @@
# requested. This will return the user to the index, or a login page, with some
# indication as to success, or a reason for failure.
import OpenBench.utils
import OpenBench.views
from OpenBench.models import *
@@ -59,6 +60,10 @@ def modify_workload(request, id, action=None):
LogEvent.objects.create(author=request.user.username, summary=action, log_file='', test_id=id)
workload.save()
# A Pipeline waiting on this Workload needs to know that it is over
if action in ['STOP', 'DELETE']:
OpenBench.utils.notify_pipelines(workload.id)
# Send back to the index, notifying them of the success
return OpenBench.views.redirect(request, '/index/', status=message)