Documentation
¶
Index ¶
- Variables
- func ContextWithUser(ctx context.Context, user string) context.Context
- func DataToMap(columns []string, data [][]any) []map[string]any
- func UserContext(ctx context.Context) string
- type Cell
- type CellResult
- type ColumnType
- type ColumnTypeTemplate
- type Content
- type ContextKey
- type Database
- type Dependency
- type EnableValue
- type Encoding
- type IDName
- type MapType
- type Mode
- type Note
- type Process
- type ProcessAction
- type ProcessActionRequest
- type ProcessCellInfo
- type ProcessInfo
- type ProcessStatus
- type Result
- type Service
- func (s *Service) ActionProcessID(ctx context.Context, pid string, action ProcessActionRequest) error
- func (s *Service) CancelProcess(pid string) bool
- func (s *Service) CleanupStaleProcesses(ctx context.Context)
- func (s *Service) CompleteProcess(ctx context.Context, pid string, rowsAffected int64, duration time.Duration)
- func (s *Service) CompleteProcessWithCells(ctx context.Context, pid string, rowsAffected int64, duration time.Duration, ...)
- func (s *Service) CreateProcess(ctx context.Context, info ProcessInfo, cancel context.CancelFunc) (string, error)
- func (s *Service) DatabaseDriverType(name string) string
- func (s *Service) DatabaseList() []string
- func (s *Service) DeleteNote(ctx context.Context, id string) error
- func (s *Service) FailProcess(ctx context.Context, pid string, processErr error, duration time.Duration)
- func (s *Service) FailProcessWithCells(ctx context.Context, pid string, processErr error, duration time.Duration, ...)
- func (s *Service) GetNote(ctx context.Context, id string) (*Note, error)
- func (s *Service) GetNoteCellDBInfo(ctx context.Context, notePath string, cellPath string) (database string, driver string)
- func (s *Service) GetNotes(ctx context.Context) ([]IDName, error)
- func (s *Service) GetProcess(ctx context.Context, q *query.Query) ([]Process, error)
- func (s *Service) GetProcessID(ctx context.Context, pid string) (*Process, error)
- func (s *Service) RegisterCancel(pid string, cancel context.CancelFunc)
- func (s *Service) RemoveCancel(pid string)
- func (s *Service) Run(ctx context.Context, cell *Cell, values map[string]any, ...) (result Result, err error)
- func (s *Service) RunNote(ctx context.Context, notePath string, values map[string]any, withResults bool) (cellInfos []ProcessCellInfo, cellResults []CellResult, err error)
- func (s *Service) RunNoteCell(ctx context.Context, notePath string, cellPath string, values map[string]any) (result Result, err error)
- func (s *Service) SaveNote(ctx context.Context, note *Note) error
- func (s *Service) StartAlan(ctx context.Context) error
- func (s *Service) StartProcessCleanup(ctx context.Context, retention, interval time.Duration)
- func (s *Service) StopAlan() error
- type SkipError
- type Storer
- type Template
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotExists = errors.New("not exist") ErrBadRequest = errors.New("bad request") )
Functions ¶
func UserContext ¶
Types ¶
type Cell ¶
type Cell struct {
ID string `json:"id"`
DBType string `json:"db_type"`
Content string `json:"content"`
Limit int64 `json:"limit"`
Mode types.Null[Mode] `json:"mode,omitzero"`
Description types.Null[string] `json:"description,omitzero"`
Collapsed types.Null[bool] `json:"collapsed,omitzero"`
Enabled types.Null[bool] `json:"enabled,omitzero"`
Result types.Null[bool] `json:"result,omitzero"`
Template Template `json:"template"`
Path types.Null[string] `json:"path,omitzero"`
Dependency types.Null[Dependency] `json:"dependency,omitzero"`
}
type CellResult ¶ added in v0.2.5
CellResult holds query result data for a single cell execution. Returned to the HTTP caller but NOT stored in the process log.
type ColumnType ¶
type ColumnTypeTemplate ¶
type ColumnTypeTemplate struct {
Type string `json:"type"`
Nullable bool `json:"nullable"`
Template EnableValue `json:"template"`
Encoding Encoding `json:"encoding"`
}
type Database ¶
type Database interface {
DatabaseList() []string
DatabaseDriverType(name string) string
Query(ctx context.Context, name, query string, limit int64) (Result, error)
Exec(ctx context.Context, name, query string) (Result, error)
IterGet(ctx context.Context, name, query string, mapType MapType) ([]string, iter.Seq2[[]any, error], error)
IterSet(ctx context.Context, name, table string, wipe bool, skipError SkipError, mapType MapType, batch int, columns []string, rows iter.Seq2[[]any, error]) (Result, error)
}
type Dependency ¶ added in v0.1.7
type EnableValue ¶
type MapType ¶
type MapType struct {
Enabled bool `json:"enabled"`
Column map[string]ColumnType `json:"column"`
Destination map[string]ColumnTypeTemplate `json:"destination"`
}
type Process ¶ added in v0.2.0
type Process struct {
ID string `json:"id"`
Status ProcessStatus `json:"status"`
Info ProcessInfo `json:"info"`
User types.Null[string] `json:"user,omitzero"`
CreatedAt types.Time `json:"created_at"`
UpdatedAt types.Time `json:"updated_at"`
}
type ProcessAction ¶ added in v0.2.0
type ProcessAction string
const (
ProcessActionTerminate ProcessAction = "terminate"
)
type ProcessActionRequest ¶ added in v0.2.0
type ProcessActionRequest struct {
Action ProcessAction `json:"action"`
}
type ProcessCellInfo ¶ added in v0.2.0
type ProcessCellInfo struct {
Description string `json:"description,omitempty"`
Query string `json:"query,omitempty"`
Database string `json:"database,omitempty"`
Driver string `json:"driver,omitempty"`
Status string `json:"status"`
Duration string `json:"duration,omitempty"`
Error string `json:"error,omitempty"`
RowsAffected int64 `json:"rows_affected,omitempty"`
}
type ProcessInfo ¶ added in v0.2.0
type ProcessInfo struct {
Note string `json:"note,omitempty"`
Query string `json:"query,omitempty"`
Description string `json:"description,omitempty"`
Database string `json:"database,omitempty"`
Driver string `json:"driver,omitempty"`
RowsAffected int64 `json:"rows_affected,omitempty"`
Error string `json:"error,omitempty"`
Duration string `json:"duration,omitempty"`
Cells []ProcessCellInfo `json:"cells,omitempty"`
}
type ProcessStatus ¶ added in v0.2.0
type ProcessStatus string
const ( ProcessStatusRunning ProcessStatus = "running" ProcessStatusCompleted ProcessStatus = "completed" ProcessStatusFailed ProcessStatus = "failed" ProcessStatusTerminated ProcessStatus = "terminated" )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) ActionProcessID ¶ added in v0.2.0
func (*Service) CancelProcess ¶ added in v0.2.0
CancelProcess invokes and removes the cancel function for a process ID. If not found locally and alan is configured, broadcasts to peers. Returns true if a cancel function was found and invoked (locally or on a peer).
func (*Service) CleanupStaleProcesses ¶ added in v0.2.0
CleanupStaleProcesses marks all running processes as failed on startup.
func (*Service) CompleteProcess ¶ added in v0.2.0
func (s *Service) CompleteProcess(ctx context.Context, pid string, rowsAffected int64, duration time.Duration)
CompleteProcess updates a process to completed status with result info.
func (*Service) CompleteProcessWithCells ¶ added in v0.2.0
func (s *Service) CompleteProcessWithCells(ctx context.Context, pid string, rowsAffected int64, duration time.Duration, cells []ProcessCellInfo)
CompleteProcessWithCells updates a process to completed status with result info and cell details.
func (*Service) CreateProcess ¶ added in v0.2.0
func (s *Service) CreateProcess(ctx context.Context, info ProcessInfo, cancel context.CancelFunc) (string, error)
CreateProcess creates a new process record with running status, registers the cancel function, and returns the process ID.
func (*Service) DatabaseDriverType ¶ added in v0.2.5
func (*Service) DatabaseList ¶
func (*Service) FailProcess ¶ added in v0.2.0
func (s *Service) FailProcess(ctx context.Context, pid string, processErr error, duration time.Duration)
FailProcess updates a process to failed status with error info.
func (*Service) FailProcessWithCells ¶ added in v0.2.0
func (s *Service) FailProcessWithCells(ctx context.Context, pid string, processErr error, duration time.Duration, cells []ProcessCellInfo)
FailProcessWithCells updates a process to failed status with error info and cell details.
func (*Service) GetNoteCellDBInfo ¶ added in v0.2.5
func (s *Service) GetNoteCellDBInfo(ctx context.Context, notePath string, cellPath string) (database string, driver string)
GetNoteCellDBInfo returns the database name and driver type for a specific cell in a note.
func (*Service) GetProcess ¶ added in v0.2.0
func (*Service) GetProcessID ¶ added in v0.2.0
func (*Service) RegisterCancel ¶ added in v0.2.0
func (s *Service) RegisterCancel(pid string, cancel context.CancelFunc)
RegisterCancel stores a cancel function for a process ID.
func (*Service) RemoveCancel ¶ added in v0.2.0
RemoveCancel removes the cancel function for a process ID without invoking it.
func (*Service) RunNote ¶
func (s *Service) RunNote(ctx context.Context, notePath string, values map[string]any, withResults bool) (cellInfos []ProcessCellInfo, cellResults []CellResult, err error)
func (*Service) RunNoteCell ¶ added in v0.1.4
func (*Service) StartAlan ¶ added in v0.2.0
StartAlan starts the alan peer communication. Blocks until ctx is cancelled. Returns nil immediately if alan is not configured.
func (*Service) StartProcessCleanup ¶ added in v0.2.2
StartProcessCleanup runs periodic cleanup of old process records. If alan is configured, a distributed lock ensures only one instance runs the cleanup loop. Other instances block on Lock until the holder exits or crashes, then one takes over automatically. Blocks until ctx is cancelled.
type Storer ¶
type Storer interface {
Get(ctx context.Context, id string) (*Note, error)
GetWithPath(ctx context.Context, path string) (*Note, error)
GetNotes(ctx context.Context) ([]IDName, error)
Save(ctx context.Context, note *Note) error
Delete(ctx context.Context, id string) error
GetProcess(ctx context.Context, q *query.Query) ([]Process, error)
SaveProcess(ctx context.Context, process *Process) error
DeleteProcessBefore(ctx context.Context, before time.Time) (int64, error)
}