153 lines
9.2 KiB
Go

package store
import (
"context"
"errors"
"time"
"droboticflow/internal/domain"
)
var (
ErrDuplicateOrganizationSlug = errors.New("organization slug must be unique")
ErrDuplicateUserEmail = errors.New("user email must be unique")
)
type WorkerRunCounts struct {
ActiveByWorkflow map[string]int
InflightByWorkflow map[string]int
ActiveTotal int
QueuedTotal int
}
type Store interface {
Ready(context.Context) error
EnsureDefaultOrganization(context.Context) (*domain.OrganizationRecord, error)
ListOrganizations(context.Context) ([]domain.OrganizationRecord, error)
GetOrganization(context.Context, string) (*domain.OrganizationRecord, error)
UpsertOrganization(context.Context, domain.OrganizationRecord) error
DeleteOrganizationCascade(context.Context, string) (bool, error)
ListProjects(context.Context) ([]domain.ProjectRecord, error)
ListProjectsByOrganization(context.Context, string) ([]domain.ProjectRecord, error)
GetProject(context.Context, string) (*domain.ProjectRecord, error)
CreateProject(context.Context, domain.CreateProjectInput) (*domain.ProjectRecord, error)
DeleteProject(context.Context, string) (bool, error)
UpsertProject(context.Context, domain.ProjectRecord) error
ListOperators(context.Context) ([]domain.OperatorRecord, error)
ListOperatorsByOrganization(context.Context, string) ([]domain.OperatorRecord, error)
GetOperator(context.Context, string) (*domain.OperatorRecord, error)
CreateOperator(context.Context, domain.CreateOperatorInput) (*domain.OperatorRecord, error)
DeleteOperator(context.Context, string) (bool, error)
UpsertOperator(context.Context, domain.OperatorRecord) error
ListBuiltinOperatorDeletions(context.Context) ([]domain.BuiltinOperatorDeletionRecord, error)
UpsertBuiltinOperatorDeletion(context.Context, domain.BuiltinOperatorDeletionRecord) error
ListWorkflowsByProject(context.Context, string) ([]domain.WorkflowRecord, error)
ListAllWorkflows(context.Context) ([]domain.WorkflowRecord, error)
ListAllWorkflowsByOrganization(context.Context, string) ([]domain.WorkflowRecord, error)
ListWorkerWorkflows(context.Context, []string, int) ([]domain.WorkflowRecord, error)
GetWorkflow(context.Context, string) (*domain.WorkflowRecord, error)
CreateWorkflow(context.Context, domain.CreateWorkflowInput) (*domain.WorkflowRecord, error)
DeleteWorkflow(context.Context, string) (bool, error)
UpsertWorkflow(context.Context, domain.WorkflowRecord) error
// UpdateWorkflowRunState updates only a workflow's run-state fields (status,
// lastRunId, updatedAt) via a field-level write. The worker holds a workflow
// snapshot for the entire duration of a run; using UpsertWorkflow (full-document
// $set) to bump run state would clobber concurrent PUT edits such as a node's
// containerCommand made while the run is in flight (a lost update). This method
// never touches Nodes/Edges, so PUT edits survive a long-running workflow.
UpdateWorkflowRunState(context.Context, string, domain.WorkflowStatus, string, string) error
ListTemplates(context.Context) ([]domain.TemplateRecord, error)
ListTemplatesByOrganization(context.Context, string) ([]domain.TemplateRecord, error)
GetTemplate(context.Context, string) (*domain.TemplateRecord, error)
CreateTemplate(context.Context, domain.CreateTemplateInput) (*domain.TemplateRecord, error)
DeleteTemplate(context.Context, string) (bool, error)
UpsertTemplate(context.Context, domain.TemplateRecord) error
ListRuns(context.Context, string) ([]domain.RunRecord, error)
ListRunsByOrganization(context.Context, string, string) ([]domain.RunRecord, error)
ListRunArtifacts(context.Context, string) ([]domain.RunRecord, error)
ListRunArtifactsByOrganization(context.Context, string, string) ([]domain.RunRecord, error)
CountRunsByStatus(context.Context) (map[domain.RunStatus]int, error)
ListRunSummaries(context.Context, string) ([]domain.RunSummary, error)
ListRunSummariesByOrganization(context.Context, string, string) ([]domain.RunSummary, error)
ListRunSummariesPage(context.Context, domain.RunSummaryQuery) (domain.RunSummaryPage, error)
ListRunSummariesPageByOrganization(context.Context, string, domain.RunSummaryQuery) (domain.RunSummaryPage, error)
ListReconcileRunSummaries(context.Context, int) ([]domain.RunSummary, error)
CountWorkerRuns(context.Context) (WorkerRunCounts, error)
HasActiveRun(context.Context, string) (bool, error)
GetRun(context.Context, string) (*domain.RunRecord, error)
CreateRun(context.Context, string, domain.RunTrigger) (*domain.RunRecord, error)
ClaimNextQueuedRun(context.Context, string, time.Duration) (*domain.RunRecord, error)
ClaimQueuedRun(context.Context, string, string, time.Duration) (*domain.RunRecord, error)
AcquireRunLease(context.Context, string, string, time.Duration) (*domain.RunRecord, bool, error)
RenewRunLease(context.Context, string, string, time.Duration) (bool, error)
ReleaseRunLease(context.Context, string, string) error
RequestRunStop(context.Context, string, domain.RunStopMode) (*domain.RunRecord, error)
UpsertRun(context.Context, domain.RunRecord) error
UpdateRunProgress(context.Context, string, *domain.RunProgress) error
UpdateRunFailure(context.Context, string, *domain.RunFailure) error
// AppendNodeExecutionResourceSample pushes one resource sample onto a running
// node's resourceSeries in place, so the worker can stream live GPU metrics for
// custom-container operators during execution (their full series is otherwise
// only persisted at node completion). No-op when the run or node is absent.
AppendNodeExecutionResourceSample(context.Context, string, string, domain.ResourceSample) error
GetSourceState(context.Context, string, string, string) (*domain.SourceStateRecord, error)
ListSourceStates(context.Context, string, string) ([]domain.SourceStateRecord, error)
UpsertSourceState(context.Context, domain.SourceStateRecord) error
DeleteSourceState(context.Context, string, string, string) error
DeleteSourceStatesByWorkflow(context.Context, string) error
ListAuditTasks(context.Context, string) ([]domain.AuditTaskRecord, error)
ListAuditTasksByOrganization(context.Context, string, string) ([]domain.AuditTaskRecord, error)
GetAuditTask(context.Context, string) (*domain.AuditTaskRecord, error)
CreateAuditTask(context.Context, domain.AuditTaskRecord) (*domain.AuditTaskRecord, error)
UpsertAuditTask(context.Context, domain.AuditTaskRecord) error
ListSamplingTasks(context.Context, string) ([]domain.SamplingTaskRecord, error)
ListSamplingTasksByOrganization(context.Context, string, string) ([]domain.SamplingTaskRecord, error)
GetSamplingTask(context.Context, string) (*domain.SamplingTaskRecord, error)
CreateSamplingTask(context.Context, domain.SamplingTaskRecord) (*domain.SamplingTaskRecord, error)
UpsertSamplingTask(context.Context, domain.SamplingTaskRecord) error
ListUsers(context.Context) ([]domain.UserRecord, error)
ListUsersByOrganization(context.Context, string) ([]domain.UserRecord, error)
GetUser(context.Context, string) (*domain.UserRecord, error)
FindUserByEmail(context.Context, string) (*domain.UserRecord, error)
CreateUser(context.Context, domain.CreateUserInput) (*domain.UserRecord, error)
DeleteUser(context.Context, string) (bool, error)
UpsertUser(context.Context, domain.UserRecord) error
CreateSession(context.Context, domain.SessionRecord) (*domain.SessionRecord, error)
GetSessionByTokenHash(context.Context, string) (*domain.SessionRecord, error)
DeleteSession(context.Context, string) (bool, error)
DeleteSessionsByUser(context.Context, string) error
ListStorageConnections(context.Context) ([]domain.StorageConnectionRecord, error)
ListStorageConnectionsByOrganization(context.Context, string) ([]domain.StorageConnectionRecord, error)
GetStorageConnection(context.Context, string) (*domain.StorageConnectionRecord, error)
CreateStorageConnection(context.Context, domain.CreateStorageConnectionInput) (*domain.StorageConnectionRecord, error)
DeleteStorageConnection(context.Context, string) (bool, error)
UpsertStorageConnection(context.Context, domain.StorageConnectionRecord) error
ListMongoConnections(context.Context) ([]domain.MongoConnectionRecord, error)
ListMongoConnectionsByOrganization(context.Context, string) ([]domain.MongoConnectionRecord, error)
GetMongoConnection(context.Context, string) (*domain.MongoConnectionRecord, error)
CreateMongoConnection(context.Context, domain.CreateMongoConnectionInput) (*domain.MongoConnectionRecord, error)
DeleteMongoConnection(context.Context, string) (bool, error)
UpsertMongoConnection(context.Context, domain.MongoConnectionRecord) error
GetSettings(context.Context) (*domain.SettingsRecord, error)
UpsertSettings(context.Context, domain.SettingsRecord) error
GetDashboardSummary(context.Context) (domain.DashboardSummary, error)
ListStorageBuckets(context.Context, string) ([]string, error)
ListStorageObjects(context.Context, string, string, string) ([]string, error)
GetDatabaseOverview(context.Context) (domain.DatabaseOverview, error)
QueryDatabaseCollection(context.Context, domain.DatabaseQueryInput) (domain.DatabaseQueryResult, error)
PatchDatabaseDocument(context.Context, string, string, map[string]any) (map[string]any, error)
UpsertDatabaseDocument(context.Context, string, map[string]any, map[string]any, map[string]any) (map[string]any, bool, error)
}