executions

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package executions runs SQL on an engine target through the query execution workflow, and reads, cancels and lists the runs. The caller resolves and authorizes the target and checks access to the workspace.

Index

Constants

View Source
const TaskQueue = "baleia-task-queue"

TaskQueue is the worker queue the execution workflow runs on.

Variables

View Source
var ErrNotFound = errors.New("executions: not found")

ErrNotFound: no execution (or statement) has this id in the workspace.

Functions

func WorkflowID

func WorkflowID(executionID db.UUID) string

WorkflowID is the id of an execution's workflow.

Types

type Config

type Config struct {
	StatementTimeout time.Duration
	ExecutionTimeout time.Duration
	// WorkloadEnabled records the workload class on new runs (#399). Off by
	// default; the admission workflow that reads it ships later.
	WorkloadEnabled bool
	// Logger receives the logs; nil discards them (#379).
	Logger *slog.Logger
}

Config are the execution settings, resolved by the caller.

type Dialects

type Dialects interface {
	ForEngineKind(kind string) (dialect.Dialect, bool)
}

Dialects says how an engine kind splits SQL; *dialect.Registry implements it.

type Engines

type Engines interface {
	Get(ctx context.Context, engineID db.UUID) (queryengine.Engine, error)
	DefaultTrino(ctx context.Context) (queryengine.Engine, error)
}

Engines finds the engine an execution ran on; the engine manager implements it.

type History

type History interface {
	ListExecutionHistory(ctx context.Context, arg db.ListExecutionHistoryParams) ([]db.ListExecutionHistoryRow, error)
	IsWorkspaceStructuralOwner(ctx context.Context, arg db.IsWorkspaceStructuralOwnerParams) (bool, error)
	ListQueryStatementsByWorkspace(ctx context.Context, arg db.ListQueryStatementsByWorkspaceParams) ([]db.QueryStatement, error)
	GetQueryStatementByPosition(ctx context.Context, arg db.GetQueryStatementByPositionParams) (db.QueryStatement, error)
}

History reads past executions and their statements; *repo.Repo implements it.

type Page

type Page struct {
	Rows []db.ListExecutionHistoryRow
	More bool
}

Page is one page of history: Rows, and More when another page follows.

type Queues

type Queues interface {
	ListEngineQueueCapacities(ctx context.Context, engineID db.UUID) ([]db.EngineQueueCapacity, error)
	GetEngineByID(ctx context.Context, id db.UUID) (db.Engine, error)
	ListWorkloadRules(ctx context.Context) ([]db.WorkloadRule, error)
}

Queues reads the per-engine workload capacities and the workload rules (#399); *repo.Repo implements it.

type Run

type Run struct {
	WorkspaceID  db.UUID
	UserID       db.UUID
	SavedQueryID db.UUID
	SQL          string
	Target       queryengine.Target
	// Identity is who the engine sees: the per-user identity and, for an
	// agent, its id.
	Identity  queryengine.Identity
	AgentID   db.UUID
	RequestID string
	// RerunOf copies the statements of a previous execution from
	// RerunFromPosition instead of re-splitting SQL (#111).
	RerunOf           db.UUID
	RerunFromPosition int32
	// Origin is where the run came from; classification uses it (#399).
	Origin workload.Origin
	// Role is the caller's global role, matched by admin rules (#546).
	Role string
	// TeamID is the workspace owner team, matched by admin rules (#546).
	TeamID db.UUID
	// AgentMaxConcurrent is the agent policy's per-agent concurrency limit,
	// enforced by admission instead of refusing the run (#589).
	AgentMaxConcurrent int
}

Run is one execution to start on a resolved target.

type Runs

type Runs interface {
	CreateQueryExecution(ctx context.Context, arg db.CreateQueryExecutionParams) (db.QueryExecution, error)
	UpdateQueryExecution(ctx context.Context, arg db.UpdateQueryExecutionParams) (db.QueryExecution, error)
	GetQueryExecutionByIDAndWorkspace(ctx context.Context, arg db.GetQueryExecutionByIDAndWorkspaceParams) (db.QueryExecution, error)
	CancelQueryExecution(ctx context.Context, arg db.CancelQueryExecutionParams) (db.QueryExecution, error)
	FailQueryExecution(ctx context.Context, arg db.FailQueryExecutionParams) (db.QueryExecution, error)
	ListRunningStatementHandles(ctx context.Context, executionID db.UUID) ([]db.ListRunningStatementHandlesRow, error)
}

Runs persists executions; *repo.Repo implements it.

type Scope

type Scope interface {
	ListWorkspaceTargets(ctx context.Context, workspaceID db.UUID) ([]db.ListWorkspaceTargetsRow, error)
}

Scope reads the workspace catalog scope a session may reach (ADR 0018 §5); *repo.Repo implements it.

type Service

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

Service runs and reads executions.

func New

func New(store Store, workflows Workflows, engines Engines, dialects Dialects, cfg Config) *Service

New builds the service. engines may be nil, in which case a cancel only stops the workflow; dialects may be nil, in which case every script is split as Trino.

func (*Service) Cancel

func (s *Service) Cancel(ctx context.Context, ws, id db.UUID) (execution db.QueryExecution, cancelled bool, err error)

Cancel stops a running execution: only a running row becomes cancelled, so a completion racing this call is never overwritten. It then cancels the workflow and, best effort, the statements still running on the engine. cancelled is false when the execution had already finished; the execution is then returned as it is.

func (*Service) Get

func (s *Service) Get(ctx context.Context, ws, id db.UUID) (db.QueryExecution, error)

Get returns one execution of the workspace.

func (*Service) History

func (s *Service) History(ctx context.Context, v Viewer, q db.ListExecutionHistoryParams, limit int) (Page, error)

History lists a page of the workspace's executions, newest first. The workspace owner and administrators see every execution and may filter by user (q.UserID); everyone else sees only their own (#36).

func (*Service) Start

func (s *Service) Start(ctx context.Context, r Run) (db.QueryExecution, error)

Start records the execution as running and starts its workflow. When the workflow cannot start, the row is failed so it never stays running.

func (*Service) Statement

func (s *Service) Statement(ctx context.Context, ws, executionID db.UUID, position int32) (db.QueryStatement, error)

Statement returns one statement of an execution of the workspace.

func (*Service) Statements

func (s *Service) Statements(ctx context.Context, ws, id db.UUID) ([]db.QueryStatement, error)

Statements returns the statements of an execution of the workspace. A foreign or absent execution is ErrNotFound, never an empty list.

func (*Service) Visible

func (s *Service) Visible(ctx context.Context, v Viewer, ws db.UUID, exec db.QueryExecution) (bool, error)

Visible reports whether the viewer may read exec: the workspace owner, an administrator, or the user who ran it (#611).

type Store

type Store interface {
	Runs
	History
	Queues
	Scope
}

Store is Runs, History and the workload queues.

type Viewer

type Viewer struct {
	UserID db.UUID
	// Admin is a platform administrator.
	Admin bool
}

Viewer is who lists the history.

type Workflows

type Workflows interface {
	ExecuteWorkflow(ctx context.Context, options client.StartWorkflowOptions, workflow any, args ...any) (client.WorkflowRun, error)
	CancelWorkflow(ctx context.Context, workflowID, runID string) error
}

Workflows starts and cancels Temporal workflows; client.Client implements it.

Jump to

Keyboard shortcuts

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