statebackend

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveRunnerID

func DeriveRunnerID() string

DeriveRunnerID builds a stable runner identifier from the environment. In GitHub Actions it includes the GITHUB_JOB and GITHUB_RUN_ID so that concurrent matrix jobs have distinct identifiers.

Types

type Backend

type Backend interface {
	// InitRun creates or joins a run for the given plan. Returns the run handle.
	InitRun(ctx context.Context, plan *model.Plan, opts InitRunOptions) (*RunHandle, error)

	// ClaimJob attempts to claim a job for this runner. The caller must inspect
	// ClaimResult to decide whether to execute, wait, or exit.
	ClaimJob(ctx context.Context, runID string, job model.PlanJob, runnerID string) (*ClaimResult, error)

	// Heartbeat signals that the runner is still alive for the given job.
	Heartbeat(ctx context.Context, runID string, jobID string, runnerID string) (*HeartbeatResult, error)

	// UpdateJob sends the terminal status for a job.
	UpdateJob(ctx context.Context, runID string, jobID string, runnerID string, status JobStatus, errText string) error

	// AppendStepLog appends step output to the job-level log.
	AppendStepLog(ctx context.Context, runID string, jobID string, content string) error

	// RunnableJobs returns the list of job IDs that are currently runnable for the given run.
	RunnableJobs(ctx context.Context, runID string) ([]string, error)

	// LoadRunState reads run state for display (status/logs commands).
	LoadRunState(ctx context.Context, runID string) (*state.ExecState, *state.ExecMetadata, error)

	// ReadJobLog retrieves the combined log for a job.
	ReadJobLog(ctx context.Context, runID string, jobID string) (string, error)

	// Close releases any resources held by the backend.
	Close(ctx context.Context) error
}

Backend is the state backend seam. Local filesystem state and remote HTTP state each implement this interface so the runner and commands can use either without embedding transport details.

type ClaimResult

type ClaimResult struct {
	Claimed       bool
	Takeover      bool
	CurrentStatus string // backend job status when not claimed
	DepsWaiting   bool
	DepsBlocked   bool
}

ClaimResult describes the outcome of a ClaimJob call.

type FileStateBackend

type FileStateBackend struct {
	Store *state.Store
}

FileStateBackend implements Backend using the local .orun/ filesystem store. It is a thin adapter so that status and logs commands can use the same interface regardless of whether remote state is active.

func NewFileStateBackend

func NewFileStateBackend(store *state.Store) *FileStateBackend

NewFileStateBackend wraps an existing state.Store.

func (*FileStateBackend) AppendStepLog

func (f *FileStateBackend) AppendStepLog(_ context.Context, _, _, _ string) error

AppendStepLog is a no-op locally — the runner writes logs via writeStepLog.

func (*FileStateBackend) ClaimJob

ClaimJob always succeeds locally — there is no concurrent runner to compete with.

func (*FileStateBackend) Close

func (f *FileStateBackend) Close(_ context.Context) error

func (*FileStateBackend) Heartbeat

func (f *FileStateBackend) Heartbeat(_ context.Context, _, _, _ string) (*HeartbeatResult, error)

Heartbeat is a no-op locally.

func (*FileStateBackend) InitRun

func (f *FileStateBackend) InitRun(_ context.Context, plan *model.Plan, opts InitRunOptions) (*RunHandle, error)

func (*FileStateBackend) LoadRunState

func (f *FileStateBackend) LoadRunState(_ context.Context, runID string) (*state.ExecState, *state.ExecMetadata, error)

func (*FileStateBackend) ReadJobLog

func (f *FileStateBackend) ReadJobLog(_ context.Context, runID string, jobID string) (string, error)

ReadJobLog concatenates all per-step log files for the given job.

func (*FileStateBackend) RunnableJobs

func (f *FileStateBackend) RunnableJobs(_ context.Context, _ string) ([]string, error)

RunnableJobs is a no-op locally — all jobs are considered runnable.

func (*FileStateBackend) UpdateJob

func (f *FileStateBackend) UpdateJob(_ context.Context, _, _, _ string, _ JobStatus, _ string) error

UpdateJob is a no-op locally — the runner updates local state directly.

type HeartbeatResult

type HeartbeatResult struct {
	OK bool
}

HeartbeatResult is returned by Heartbeat.

type InitRunOptions

type InitRunOptions struct {
	RunID       string
	DryRun      bool
	Actor       string
	TriggerType string
}

InitRunOptions carries options for InitRun.

type JobStatus

type JobStatus string

JobStatus mirrors the backend API terminal status values.

const (
	JobStatusSuccess JobStatus = "success"
	JobStatusFailed  JobStatus = "failed"
)

type RemoteStateBackend

type RemoteStateBackend struct {
	// contains filtered or unexported fields
}

RemoteStateBackend implements Backend using the orun-backend HTTP API.

func NewRemoteStateBackend

func NewRemoteStateBackend(client *remotestate.Client, runnerID string) *RemoteStateBackend

NewRemoteStateBackend creates a RemoteStateBackend with the given HTTP client and runner identifier. runnerID should be unique per runner instance.

func (*RemoteStateBackend) AppendStepLog

func (r *RemoteStateBackend) AppendStepLog(ctx context.Context, runID string, jobID string, content string) error

func (*RemoteStateBackend) ClaimJob

func (r *RemoteStateBackend) ClaimJob(ctx context.Context, runID string, job model.PlanJob, runnerID string) (*ClaimResult, error)

func (*RemoteStateBackend) Close

func (*RemoteStateBackend) Heartbeat

func (r *RemoteStateBackend) Heartbeat(ctx context.Context, runID string, jobID string, runnerID string) (*HeartbeatResult, error)

func (*RemoteStateBackend) InitRun

func (r *RemoteStateBackend) InitRun(ctx context.Context, plan *model.Plan, opts InitRunOptions) (*RunHandle, error)

func (*RemoteStateBackend) LoadRunState

func (r *RemoteStateBackend) LoadRunState(ctx context.Context, runID string) (*state.ExecState, *state.ExecMetadata, error)

func (*RemoteStateBackend) ReadJobLog

func (r *RemoteStateBackend) ReadJobLog(ctx context.Context, runID string, jobID string) (string, error)

func (*RemoteStateBackend) RunnableJobs

func (r *RemoteStateBackend) RunnableJobs(ctx context.Context, runID string) ([]string, error)

func (*RemoteStateBackend) UpdateJob

func (r *RemoteStateBackend) UpdateJob(ctx context.Context, runID string, jobID string, runnerID string, status JobStatus, errText string) error

type RunHandle

type RunHandle struct {
	RunID string
}

RunHandle is returned by InitRun.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL