package models import ( "context" "github.com/bluesky-social/indigo/atproto/syntax" ) // Adapter is the core of the spindle. It can use its own way to configure and // run the workflows. The workflow definition can be either yaml files in git // repositories or even from dedicated web UI. // // An adapter is expected to be hold all created workflow runs. type Adapter interface { // Init intializes the adapter Init() error // Shutdown gracefully shuts down background jobs Shutdown(ctx context.Context) error // SetupRepo ensures adapter connected to the repository. // This usually includes adding repository watcher that does sparse-clone. SetupRepo(ctx context.Context, repo syntax.ATURI) error // ListWorkflowDefs parses and returns all workflow definitions in the given // repository at the specified revision ListWorkflowDefs(ctx context.Context, repo syntax.ATURI, rev string) ([]WorkflowDef, error) // EvaluateEvent consumes a trigger event and returns a list of triggered // workflow runs. It is expected to return immediately after scheduling the // workflows. EvaluateEvent(ctx context.Context, event Event) ([]WorkflowRun, error) // GetActiveWorkflowRun returns current state of specific workflow run. // This method will be called regularly for active workflow runs. GetActiveWorkflowRun(ctx context.Context, runId syntax.ATURI) (WorkflowRun, error) // NOTE: baisically I'm not sure about this method. // How to properly sync workflow.run states? // // for adapters with external engine, they will hold every past // workflow.run objects. // for adapters with internal engine, they... should also hold every // past workflow.run objects..? // // problem: // when spindle suffer downtime (spindle server shutdown), // external `workflow.run`s might be unsynced in "running" or "pending" state // same for internal `workflow.run`s. // // BUT, spindle itself is holding the runs, // so it already knows unsynced workflows (=workflows not finished) // therefore, it can just fetch them again. // for adapters with internal engines, they will fail to fetch previous // run. // Leaving spindle to mark the run as "Lost" or "Failed". // Because of _lacking_ adaters, spindle should be able to manually // mark unknown runs with "lost" state. // // GetWorkflowRun : used to get background crawling // XCodeCloud: ok // Nixery: (will fail if unknown) -> spindle will mark workflow as failed anyways // StreamWorkflowRun : used to notify real-time updates // XCodeCloud: ok (but old events will be lost) // Nixery: same. old events on spindle downtime will be lost // // // To avoid this, each adapters should hold outbox buffer // // | // v // StreamWorkflowRun(ctx context.Context) <-chan WorkflowRun // ListActiveWorkflowRuns returns current list of active workflow runs. // Runs where status is either Pending or Running ListActiveWorkflowRuns(ctx context.Context) ([]WorkflowRun, error) SubscribeWorkflowRun(ctx context.Context) <-chan WorkflowRun // StreamWorkflowRunLogs streams logs for a running workflow execution StreamWorkflowRunLogs(ctx context.Context, runId syntax.ATURI, handle func(line LogLine) error) error // CancelWorkflowRun attempts to stop a running workflow execution. // It won't do anything when the workflow has already completed. CancelWorkflowRun(ctx context.Context, runId syntax.ATURI) error }