A vibe coded tangled fork which supports pijul.
1package models
2
3import (
4 "context"
5
6 "github.com/bluesky-social/indigo/atproto/syntax"
7)
8
9// Adapter is the core of the spindle. It can use its own way to configure and
10// run the workflows. The workflow definition can be either yaml files in git
11// repositories or even from dedicated web UI.
12//
13// An adapter is expected to be hold all created workflow runs.
14type Adapter interface {
15 // Init intializes the adapter
16 Init() error
17
18 // Shutdown gracefully shuts down background jobs
19 Shutdown(ctx context.Context) error
20
21 // SetupRepo ensures adapter connected to the repository.
22 // This usually includes adding repository watcher that does sparse-clone.
23 SetupRepo(ctx context.Context, repo syntax.ATURI) error
24
25 // ListWorkflowDefs parses and returns all workflow definitions in the given
26 // repository at the specified revision
27 ListWorkflowDefs(ctx context.Context, repo syntax.ATURI, rev string) ([]WorkflowDef, error)
28
29 // EvaluateEvent consumes a trigger event and returns a list of triggered
30 // workflow runs. It is expected to return immediately after scheduling the
31 // workflows.
32 EvaluateEvent(ctx context.Context, event Event) ([]WorkflowRun, error)
33
34 // GetActiveWorkflowRun returns current state of specific workflow run.
35 // This method will be called regularly for active workflow runs.
36 GetActiveWorkflowRun(ctx context.Context, runId syntax.ATURI) (WorkflowRun, error)
37
38
39
40
41 // NOTE: baisically I'm not sure about this method.
42 // How to properly sync workflow.run states?
43 //
44 // for adapters with external engine, they will hold every past
45 // workflow.run objects.
46 // for adapters with internal engine, they... should also hold every
47 // past workflow.run objects..?
48 //
49 // problem:
50 // when spindle suffer downtime (spindle server shutdown),
51 // external `workflow.run`s might be unsynced in "running" or "pending" state
52 // same for internal `workflow.run`s.
53 //
54 // BUT, spindle itself is holding the runs,
55 // so it already knows unsynced workflows (=workflows not finished)
56 // therefore, it can just fetch them again.
57 // for adapters with internal engines, they will fail to fetch previous
58 // run.
59 // Leaving spindle to mark the run as "Lost" or "Failed".
60 // Because of _lacking_ adaters, spindle should be able to manually
61 // mark unknown runs with "lost" state.
62 //
63 // GetWorkflowRun : used to get background crawling
64 // XCodeCloud: ok
65 // Nixery: (will fail if unknown) -> spindle will mark workflow as failed anyways
66 // StreamWorkflowRun : used to notify real-time updates
67 // XCodeCloud: ok (but old events will be lost)
68 // Nixery: same. old events on spindle downtime will be lost
69 //
70 //
71 // To avoid this, each adapters should hold outbox buffer
72 //
73 // |
74 // v
75
76 // StreamWorkflowRun(ctx context.Context) <-chan WorkflowRun
77
78
79 // ListActiveWorkflowRuns returns current list of active workflow runs.
80 // Runs where status is either Pending or Running
81 ListActiveWorkflowRuns(ctx context.Context) ([]WorkflowRun, error)
82 SubscribeWorkflowRun(ctx context.Context) <-chan WorkflowRun
83
84
85
86
87 // StreamWorkflowRunLogs streams logs for a running workflow execution
88 StreamWorkflowRunLogs(ctx context.Context, runId syntax.ATURI, handle func(line LogLine) error) error
89
90 // CancelWorkflowRun attempts to stop a running workflow execution.
91 // It won't do anything when the workflow has already completed.
92 CancelWorkflowRun(ctx context.Context, runId syntax.ATURI) error
93}