Separate saved run schedules from pipeline definitions
This commit is contained in:
+20
-28
@@ -128,34 +128,20 @@ func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
|
||||
}
|
||||
|
||||
func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.RunDetail, error) {
|
||||
return r.startWithSchedule(request, nil, retryOf...)
|
||||
}
|
||||
|
||||
func (r *runner) startWithSchedule(request protocol.Message, origin *pipeline.ScheduleAdmission, retryOf ...int64) (*protocol.RunDetail, error) {
|
||||
if err := protocol.ValidateOutputFormat(request.OutputFormat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if request.Version <= 0 || request.RequestKey == "" || len(request.RequestKey) > 128 {
|
||||
return nil, fmt.Errorf("an explicit version and request key are required")
|
||||
}
|
||||
workspace, err := os.Getwd()
|
||||
workspace, err := pipeline.ResolveRunWorkspace(request.Workspace, origin != nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspace, err = filepath.EvalSymlinks(workspace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if request.Workspace != "" {
|
||||
if !filepath.IsAbs(request.Workspace) {
|
||||
return nil, fmt.Errorf("run workspace must be an absolute directory")
|
||||
}
|
||||
selected, err := filepath.EvalSymlinks(request.Workspace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("run workspace is unavailable on the execution server: %q: %w; for Docker, mount this host directory at the same absolute path and use its owner's UID/GID", request.Workspace, err)
|
||||
}
|
||||
info, err := os.Stat(selected)
|
||||
if err != nil || !info.IsDir() {
|
||||
return nil, fmt.Errorf("run workspace %q must be an accessible directory on the execution server", request.Workspace)
|
||||
}
|
||||
workspace = selected
|
||||
}
|
||||
if len(request.WritePaths) > 20 {
|
||||
return nil, fmt.Errorf("too many write paths")
|
||||
}
|
||||
@@ -293,7 +279,7 @@ func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.Ru
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
id, created, err := r.store.CreateRunTitled(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, pipeline.RunOverrides{Model: request.Model, StageModels: request.StageModels, NotifyMode: request.NotifyMode, OutputFormat: request.OutputFormat}, runTitle, retryOf...)
|
||||
id, created, err := r.store.CreateRunTitled(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, pipeline.RunOverrides{Schedule: origin, Model: request.Model, StageModels: request.StageModels, NotifyMode: request.NotifyMode, OutputFormat: request.OutputFormat}, runTitle, retryOf...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1302,26 +1288,29 @@ func (s *runState) publishServerChangedFiles() {
|
||||
// emitRun, so a client that has never seen the run can build its list row from
|
||||
// the frame without re-reading the whole list.
|
||||
type runIdentity struct {
|
||||
pipelineID int64
|
||||
name string
|
||||
title string
|
||||
version int
|
||||
scheduled bool
|
||||
scheduleID int64
|
||||
scheduleName string
|
||||
pipelineID int64
|
||||
name string
|
||||
title string
|
||||
version int
|
||||
}
|
||||
|
||||
// identityOfRunSummary is the one projection of a run row onto the identity its
|
||||
// pushed frames carry, so the frame and the list row cannot disagree.
|
||||
func identityOfRunSummary(s protocol.RunSummary) runIdentity {
|
||||
return runIdentity{pipelineID: s.PipelineID, name: s.Name, title: s.Title, version: s.Version}
|
||||
return runIdentity{scheduled: s.Scheduled, scheduleID: s.ScheduleID, scheduleName: s.ScheduleName, pipelineID: s.PipelineID, name: s.Name, title: s.Title, version: s.Version}
|
||||
}
|
||||
|
||||
// rememberRunIdentity records the identity every later frame of run id carries.
|
||||
// It is safe from any goroutine and takes its own lock (never r.mu), so it is
|
||||
// callable from a path that already holds r.mu.
|
||||
func (r *runner) rememberRunIdentity(id int64, ident runIdentity) {
|
||||
if r.idents == nil {
|
||||
return
|
||||
}
|
||||
r.identMu.Lock()
|
||||
if r.idents == nil {
|
||||
r.idents = map[int64]runIdentity{}
|
||||
}
|
||||
r.idents[id] = ident
|
||||
r.identMu.Unlock()
|
||||
}
|
||||
@@ -1336,6 +1325,9 @@ func (r *runner) stampRunIdentity(frame *protocol.RunEventFrame) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
frame.Scheduled = ident.scheduled
|
||||
frame.ScheduleID = ident.scheduleID
|
||||
frame.ScheduleName = ident.scheduleName
|
||||
if frame.PipelineID == 0 {
|
||||
frame.PipelineID = ident.pipelineID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user