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
- Variables
- func WorkflowID(executionID db.UUID) string
- type Config
- type Dialects
- type Engines
- type History
- type Page
- type Queues
- type Run
- type Runs
- type Scope
- type Service
- func (s *Service) Cancel(ctx context.Context, ws, id db.UUID) (execution db.QueryExecution, cancelled bool, err error)
- func (s *Service) Get(ctx context.Context, ws, id db.UUID) (db.QueryExecution, error)
- func (s *Service) History(ctx context.Context, v Viewer, q db.ListExecutionHistoryParams, limit int) (Page, error)
- func (s *Service) Start(ctx context.Context, r Run) (db.QueryExecution, error)
- func (s *Service) Statement(ctx context.Context, ws, executionID db.UUID, position int32) (db.QueryStatement, error)
- func (s *Service) Statements(ctx context.Context, ws, id db.UUID) ([]db.QueryStatement, error)
- func (s *Service) Visible(ctx context.Context, v Viewer, ws db.UUID, exec db.QueryExecution) (bool, error)
- type Store
- type Viewer
- type Workflows
Constants ¶
const TaskQueue = "baleia-task-queue"
TaskQueue is the worker queue the execution workflow runs on.
Variables ¶
var ErrNotFound = errors.New("executions: not found")
ErrNotFound: no execution (or statement) has this id in the workspace.
Functions ¶
func WorkflowID ¶
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 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 ¶
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) 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 ¶
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 ¶
Statements returns the statements of an execution of the workspace. A foreign or absent execution is ErrNotFound, never an empty list.
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.