···3030 did text primary key3131 );32323333- create table if not exists pipelines (3434- at_uri text not null,3333+ create table if not exists pipeline_status (3434+ rkey text not null,3535+ pipeline text not null,3536 status text not null,36373738 -- only set if status is 'failed'···4342 updated_at timestamp not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),4443 finished_at timestamp,45444646- primary key (at_uri)4545+ primary key (rkey)4746 );4847 `)4948 if err != nil {
+48-42
spindle/db/pipelines.go
···88 "tangled.sh/tangled.sh/core/knotserver/notifier"99)10101111-type PipelineStatus string1111+type PipelineRunStatus string12121313var (1414- PipelinePending PipelineStatus = "pending"1515- PipelineRunning PipelineStatus = "running"1616- PipelineFailed PipelineStatus = "failed"1717- PipelineTimeout PipelineStatus = "timeout"1818- PipelineCancelled PipelineStatus = "cancelled"1919- PipelineSuccess PipelineStatus = "success"1414+ PipelinePending PipelineRunStatus = "pending"1515+ PipelineRunning PipelineRunStatus = "running"1616+ PipelineFailed PipelineRunStatus = "failed"1717+ PipelineTimeout PipelineRunStatus = "timeout"1818+ PipelineCancelled PipelineRunStatus = "cancelled"1919+ PipelineSuccess PipelineRunStatus = "success"2020)21212222-type Pipeline struct {2323- Rkey string `json:"rkey"`2424- Knot string `json:"knot"`2525- Status PipelineStatus `json:"status"`2222+type PipelineStatus struct {2323+ Rkey string `json:"rkey"`2424+ Pipeline string `json:"pipeline"`2525+ Status PipelineRunStatus `json:"status"`26262727 // only if Failed2828 Error string `json:"error"`···3333 FinishedAt time.Time `json:"finished_at"`3434}35353636-func (p Pipeline) AsRecord() *tangled.PipelineStatus {3636+func (p PipelineStatus) AsRecord() *tangled.PipelineStatus {3737 exitCode64 := int64(p.ExitCode)3838 finishedAt := p.FinishedAt.String()39394040 return &tangled.PipelineStatus{4141- Pipeline: fmt.Sprintf("at://%s/%s", p.Knot, p.Rkey),4242- Status: string(p.Status),4141+ LexiconTypeID: tangled.PipelineStatusNSID,4242+ Pipeline: p.Pipeline,4343+ Status: string(p.Status),43444445 ExitCode: &exitCode64,4546 Error: &p.Error,···5554 return fmt.Sprintf("at://%s/did:web:%s/%s", tangled.PipelineStatusNSID, knot, rkey)5655}57565858-func (db *DB) CreatePipeline(rkey, knot string, n *notifier.Notifier) error {5757+func (db *DB) CreatePipeline(rkey, pipeline string, n *notifier.Notifier) error {5958 _, err := db.Exec(`6060- insert into pipelines (at_uri, status)6161- values (?, ?)6262- `, pipelineAtUri(rkey, knot), PipelinePending)5959+ insert into pipeline_status (rkey, status, pipeline)6060+ values (?, ?, ?)6161+ `, rkey, PipelinePending, pipeline)63626463 if err != nil {6564 return err···6867 return nil6968}70697171-func (db *DB) MarkPipelineRunning(rkey, knot string, n *notifier.Notifier) error {7070+func (db *DB) MarkPipelineRunning(rkey string, n *notifier.Notifier) error {7271 _, err := db.Exec(`7373- update pipelines7272+ update pipeline_status7473 set status = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')7575- where at_uri = ?7676- `, PipelineRunning, pipelineAtUri(rkey, knot))7474+ where rkey = ?7575+ `, PipelineRunning, rkey)77767877 if err != nil {7978 return err···8281 return nil8382}84838585-func (db *DB) MarkPipelineFailed(rkey, knot string, exitCode int, errorMsg string, n *notifier.Notifier) error {8484+func (db *DB) MarkPipelineFailed(rkey string, exitCode int, errorMsg string, n *notifier.Notifier) error {8685 _, err := db.Exec(`8787- update pipelines8686+ update pipeline_status8887 set status = ?,8988 exit_code = ?,9089 error = ?,9190 updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now'),9291 finished_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')9393- where at_uri = ?9494- `, PipelineFailed, exitCode, errorMsg, pipelineAtUri(rkey, knot))9292+ where rkey = ?9393+ `, PipelineFailed, exitCode, errorMsg, rkey)9594 if err != nil {9695 return err9796 }···9998 return nil10099}101100102102-func (db *DB) MarkPipelineTimeout(rkey, knot string, n *notifier.Notifier) error {101101+func (db *DB) MarkPipelineTimeout(rkey string, n *notifier.Notifier) error {103102 _, err := db.Exec(`104104- update pipelines103103+ update pipeline_status105104 set status = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')106106- where at_uri = ?107107- `, PipelineTimeout, pipelineAtUri(rkey, knot))105105+ where rkey = ?106106+ `, PipelineTimeout, rkey)108107 if err != nil {109108 return err110109 }···112111 return nil113112}114113115115-func (db *DB) MarkPipelineSuccess(rkey, knot string, n *notifier.Notifier) error {114114+func (db *DB) MarkPipelineSuccess(rkey string, n *notifier.Notifier) error {116115 _, err := db.Exec(`117117- update pipelines116116+ update pipeline_status118117 set status = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now'),119118 finished_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')120120- where at_uri = ?121121- `, PipelineSuccess, pipelineAtUri(rkey, knot))119119+ where rkey = ?120120+ `, PipelineSuccess, rkey)122121123122 if err != nil {124123 return err···127126 return nil128127}129128130130-func (db *DB) GetPipeline(rkey, knot string) (Pipeline, error) {131131- var p Pipeline129129+func (db *DB) GetPipelineStatus(rkey string) (PipelineStatus, error) {130130+ var p PipelineStatus132131 err := db.QueryRow(`133132 select rkey, status, error, exit_code, started_at, updated_at, finished_at134133 from pipelines135135- where at_uri = ?136136- `, pipelineAtUri(rkey, knot)).Scan(&p.Rkey, &p.Status, &p.Error, &p.ExitCode, &p.StartedAt, &p.UpdatedAt, &p.FinishedAt)134134+ where rkey = ?135135+ `, rkey).Scan(&p.Rkey, &p.Status, &p.Error, &p.ExitCode, &p.StartedAt, &p.UpdatedAt, &p.FinishedAt)137136 return p, err138137}139138140140-func (db *DB) GetPipelines(cursor string) ([]Pipeline, error) {139139+func (db *DB) GetPipelineStatusAsRecords(cursor string) ([]PipelineStatus, error) {141140 whereClause := ""142141 args := []any{}143142 if cursor != "" {···147146148147 query := fmt.Sprintf(`149148 select rkey, status, error, exit_code, started_at, updated_at, finished_at150150- from pipelines149149+ from pipeline_status151150 %s152151 order by rkey asc153152 limit 100···159158 }160159 defer rows.Close()161160162162- var pipelines []Pipeline161161+ var pipelines []PipelineStatus163162 for rows.Next() {164164- var p Pipeline163163+ var p PipelineStatus165164 rows.Scan(&p.Rkey, &p.Status, &p.Error, &p.ExitCode, &p.StartedAt, &p.UpdatedAt, &p.FinishedAt)166165 pipelines = append(pipelines, p)167166 }168167169168 if err := rows.Err(); err != nil {170169 return nil, err170170+ }171171+172172+ records := []*tangled.PipelineStatus{}173173+ for _, p := range pipelines {174174+ records = append(records, p.AsRecord())171175 }172176173177 return pipelines, nil
+2-2
spindle/engine/engine.go
···47474848// SetupPipeline sets up a new network for the pipeline, and possibly volumes etc.4949// in the future. In here also goes other setup steps.5050-func (e *Engine) SetupPipeline(ctx context.Context, pipeline *tangled.Pipeline, id string) error {5050+func (e *Engine) SetupPipeline(ctx context.Context, pipeline *tangled.Pipeline, atUri, id string) error {5151 e.l.Info("setting up pipeline", "pipeline", id)52525353 _, err := e.docker.VolumeCreate(ctx, volume.CreateOptions{···7373 return err7474 }75757676- err = e.db.CreatePipeline(id, e.n)7676+ err = e.db.CreatePipeline(id, atUri, e.n)7777 return err7878}7979