Documentation
¶
Index ¶
- Constants
- func IsDiskFull(err error) bool
- func IsUniqueViolation(err error) bool
- type Access
- type ActivityCount
- type Applied
- type Change
- type Desired
- type DesiredCounts
- type Dialect
- type GatewayResource
- type Instance
- type Job
- type ModuleRemoval
- type Network
- type Notification
- type Registration
- type Removal
- type ResourceCheck
- type RestartStats
- type RetentionTarget
- type StartEvent
- type Store
- func (this *Store) Close() error
- func (this *Store) Dialect() Dialect
- func (this *Store) DisablePermissionRemovals()
- func (this *Store) Full() bool
- func (this *Store) Ping(ctx context.Context) error
- func (this *Store) SetMaxOpenConns(n int)
- func (this *Store) Tx(ctx context.Context, fn func(tx *Tx) error) (err error)
- func (this *Store) Vacuum(ctx context.Context, pages int) error
- type Subscription
- type Subtask
- type Token
- type TokenState
- type Tx
- func (this *Tx) ActivitySeqAt(instanceId string, at time.Time) (seq int64, found bool, err error)
- func (this *Tx) AllDeployments(after string, limit int) ([]model.Deployment, error)
- func (this *Tx) BufferMessage(instanceId string, name string, variables map[string]any, at time.Time) error
- func (this *Tx) ChangesAfter(seq int64, limit int) (result []Change, err error)
- func (this *Tx) ChildInstances(parentId string) (result []string, err error)
- func (this *Tx) ClaimDueWatches(now time.Time, limit int) (result []Watch, err error)
- func (this *Tx) ClearRuntime(instanceId string) error
- func (this *Tx) ConsecutiveIncidentRuns(instanceId string) (int, error)
- func (this *Tx) CountElementPass(instanceId string, run int, elementId string, at time.Time) error
- func (this *Tx) CountIoValues(userId string) (int, error)
- func (this *Tx) CountJobs(instanceId string) (int, error)
- func (this *Tx) CountSubtaskTry(jobId string, subId string, at time.Time) error
- func (this *Tx) DatabaseBytes() (int64, error)
- func (this *Tx) DeleteDeployment(id string) error
- func (this *Tx) DeleteFinishedInstances(column string, value string, before time.Time, limit int) (int64, error)
- func (this *Tx) DeleteInstance(id string) error
- func (this *Tx) DeleteIoValue(userId string, key string) error
- func (this *Tx) DeleteJob(id string) error
- func (this *Tx) DeleteModel(id string) error
- func (this *Tx) DeleteModule(id string) error
- func (this *Tx) DeleteNamespace(name string) error
- func (this *Tx) DeleteNetwork(id string) error
- func (this *Tx) DeleteNotification(id string) error
- func (this *Tx) DeleteOwned(userId string) error
- func (this *Tx) DeleteRemoval(topic string, id string) error
- func (this *Tx) DeleteSchedule(id string) error
- func (this *Tx) DeleteSubscriptionsOfToken(tokenId string) error
- func (this *Tx) DeleteToken(id string) error
- func (this *Tx) DeleteUserSettings(userId string) error
- func (this *Tx) DeleteVariable(instanceId string, name string) error
- func (this *Tx) DeleteVariables(instanceId string) error
- func (this *Tx) DeleteWatch(id string) error
- func (this *Tx) DeploymentVersionCreated(deploymentId string, version int) (time.Time, error)
- func (this *Tx) DeploymentsAfter(afterId string, limit int) (result []RetentionTarget, err error)
- func (this *Tx) DeploymentsOfDeviceGroup(groupId string) (result []string, err error)
- func (this *Tx) DeploymentsOfOthers(id string, owner string) (count int, err error)
- func (this *Tx) Desire(networkId string, kind string, id string, deleted bool, spec any, ...) (version int64, err error)
- func (this *Tx) DesiredBacklog() (map[string]DesiredCounts, error)
- func (this *Tx) DeviceGroupsOfDeployment(deploymentId string) (result []string, err error)
- func (this *Tx) DueDesired(before time.Time, contactAfter time.Time, limit int) ([]Desired, error)
- func (this *Tx) DueModuleRemovals(now time.Time, limit int) (result []ModuleRemoval, err error)
- func (this *Tx) DueNotifications(now time.Time, limit int) (result []Notification, err error)
- func (this *Tx) DueRemovals(now time.Time, limit int) (result []Removal, err error)
- func (this *Tx) DueRestarts(now time.Time, limit int) (result []string, err error)
- func (this *Tx) DueSchedules(now time.Time, limit int) (result []model.Schedule, err error)
- func (this *Tx) DueStartTimers(now time.Time, limit int) ([]StartEvent, error)
- func (this *Tx) DueTimers(now time.Time, limit int) ([]Subscription, error)
- func (this *Tx) EnsureSubtasks(subtasks []Subtask) error
- func (this *Tx) EventDescriptionsSince(revision int64) (result []model.EventDescription, removed []string, latest int64, err error)
- func (this *Tx) FinishModuleRemoval(moduleId string) error
- func (this *Tx) ForgetEndedInstance(networkId string, id string) error
- func (this *Tx) GatewayDeploymentIds(namespace string) (result []string, err error)
- func (this *Tx) GetApplied(kind string, id string) (result Applied, found bool, err error)
- func (this *Tx) GetDeployment(id string, lock bool) (model.Deployment, error)
- func (this *Tx) GetDeploymentVersion(deploymentId string, version int) (v model.DeploymentVersion, err error)
- func (this *Tx) GetDesired(networkId string, kind string, id string) (Desired, bool, error)
- func (this *Tx) GetIncidentHandling(deploymentId string, version int) (result model.IncidentHandling, err error)
- func (this *Tx) GetInstance(id string, lock bool) (Instance, error)
- func (this *Tx) GetIoValue(userId string, key string) (result model.IoValue, ok bool, err error)
- func (this *Tx) GetJob(id string) (*Job, error)
- func (this *Tx) GetModel(id string, lock bool) (model.Model, error)
- func (this *Tx) GetModelVersion(modelId string, version int) (v model.ModelVersion, err error)
- func (this *Tx) GetModule(id string) (model.Module, error)
- func (this *Tx) GetNetwork(id string) (Network, bool, error)
- func (this *Tx) GetRestartStats(deploymentId string) (result RestartStats, err error)
- func (this *Tx) GetRun(instanceId string, run int) (r model.Run, err error)
- func (this *Tx) GetSchedule(id string) (model.Schedule, error)
- func (this *Tx) GetStartEvent(deploymentId string, elementId string) (StartEvent, error)
- func (this *Tx) GetSubscription(id string) (*Subscription, error)
- func (this *Tx) GetUserSettings(userId string) (result model.UserSettings, err error)
- func (this *Tx) GetVariables(instanceId string) (result []model.Variable, err error)
- func (this *Tx) HasReceipt(messageId string, target string) (bool, error)
- func (this *Tx) InitSyncPosition(name string) error
- func (this *Tx) InsertActivity(a model.Activity) error
- func (this *Tx) InsertDeployment(d model.Deployment) error
- func (this *Tx) InsertDeploymentVersion(v model.DeploymentVersion) error
- func (this *Tx) InsertIncident(i model.Incident) error
- func (this *Tx) InsertInstance(i Instance) error
- func (this *Tx) InsertModel(m model.Model) error
- func (this *Tx) InsertModelVersion(v model.ModelVersion) error
- func (this *Tx) InsertNamespace(ns model.Namespace, at time.Time) (bool, error)
- func (this *Tx) InsertNotification(n Notification) error
- func (this *Tx) InsertReceipt(messageId string, target string, at time.Time) (bool, error)
- func (this *Tx) InsertRun(r model.Run) error
- func (this *Tx) InsertSubscription(s Subscription) error
- func (this *Tx) InstanceIds() (result []string, err error)
- func (this *Tx) InstanceIdsOfDeployment(deploymentId string, state model.InstanceState) (result []string, err error)
- func (this *Tx) InstancesPerVersion(deploymentId string) (map[int]int, error)
- func (this *Tx) JobCandidates(now time.Time, limit int) (result []Job, err error)
- func (this *Tx) JobExists(id string) (bool, error)
- func (this *Tx) LatestChangeSeq() (result int64, err error)
- func (this *Tx) ListActivities(instanceId string, options model.ActivityListOptions) (result []model.Activity, err error)
- func (this *Tx) ListApplied() (result []Applied, err error)
- func (this *Tx) ListDeploymentVersions(deploymentId string, page model.PageOptions) (result model.Page[model.DeploymentVersion], err error)
- func (this *Tx) ListDeployments(namespace string, options model.DeploymentListOptions, access Access) (result model.Page[model.Deployment], err error)
- func (this *Tx) ListDesired(networkId string, kind string) (result []Desired, err error)
- func (this *Tx) ListElementStats(instanceId string, run int) (result []model.ElementStats, err error)
- func (this *Tx) ListEventDescriptions(deploymentId string) (result []model.EventDescription, err error)
- func (this *Tx) ListIncidents(namespace string, options model.IncidentListOptions, access Access) (result model.Page[model.Incident], err error)
- func (this *Tx) ListInstances(namespace string, options model.InstanceListOptions, access Access) (result model.Page[model.Instance], err error)
- func (this *Tx) ListIoValues(userId string, deploymentId string, instanceId string, sort string) (result []model.IoValue, err error)
- func (this *Tx) ListJobs(instanceId string) (result []Job, err error)
- func (this *Tx) ListModelVersions(modelId string, page model.PageOptions) (result model.Page[model.ModelVersion], err error)
- func (this *Tx) ListModels(namespace string, options model.ModelListOptions, access Access) (result model.Page[model.Model], err error)
- func (this *Tx) ListModules(namespace string, options model.ModuleListOptions, access Access) (result model.Page[model.Module], err error)
- func (this *Tx) ListNamespaces() (result []model.Namespace, err error)
- func (this *Tx) ListNetworks(ids []string) (result []Network, err error)
- func (this *Tx) ListRuns(instanceId string) ([]model.Run, error)
- func (this *Tx) ListSchedules(namespace string, options model.ScheduleListOptions, access Access) (result model.Page[model.Schedule], err error)
- func (this *Tx) ListSubscriptions(instanceId string) ([]Subscription, error)
- func (this *Tx) ListSubtasks(jobId string) ([]Subtask, error)
- func (this *Tx) ListTokens(instanceId string) (result []Token, err error)
- func (this *Tx) LockNetwork(id string, now time.Time) (Network, error)
- func (this *Tx) LowerDesiredApplied(networkId string, kind string, id string, version int64, message string) error
- func (this *Tx) MarkDesiredSent(networkId string, kind string, id string, version int64, at time.Time) error
- func (this *Tx) MarkNamespaceUnregistered(kind model.Kind, namespace string) error
- func (this *Tx) MarkRegistered(kind model.Kind, id string, owner string) (bool, error)
- func (this *Tx) MarkUnregistered(kind model.Kind, id string) error
- func (this *Tx) MessageStartEvents(messageName string, owner string) ([]StartEvent, error)
- func (this *Tx) MessageSubscriptions(messageName string, instanceId string, owner string) ([]Subscription, error)
- func (this *Tx) ModelsAfter(afterId string, limit int) (result []string, err error)
- func (this *Tx) ModuleErrors(instanceIds []string) (map[string]model.Module, error)
- func (this *Tx) ModulesOfInstance(instanceId string, key string, moduleType string) ([]model.Module, error)
- func (this *Tx) ModulesToCheck(moduleType string, before time.Time, limit int) ([]model.Module, error)
- func (this *Tx) NamespaceInUse(name string) (bool, error)
- func (this *Tx) NetworkInstanceIds(networkId string) (result []string, err error)
- func (this *Tx) NetworksWithDeployments() ([]string, error)
- func (this *Tx) NextJobDue() (*time.Time, error)
- func (this *Tx) NextRestartDue() (*time.Time, error)
- func (this *Tx) NextStartTimerDue() (*time.Time, error)
- func (this *Tx) NextTimerDue() (*time.Time, error)
- func (this *Tx) OldestChangeSeq() (result int64, err error)
- func (this *Tx) OldestSnapshotSeq(instanceId string) (seq int64, found bool, err error)
- func (this *Tx) OwnedCounts(userId string) (map[string]int, error)
- func (this *Tx) OwnedOnGateways(userId string) (result []GatewayResource, err error)
- func (this *Tx) Owner(kind model.Kind, id string) (owner string, namespace string, ok bool, err error)
- func (this *Tx) PendingRegistrations(kind model.Kind, limit int) (result []Registration, err error)
- func (this *Tx) PruneAppliedInstances() (int64, error)
- func (this *Tx) PurgeChanges(before time.Time, limit int) (int64, error)
- func (this *Tx) PurgeEventTombstones(before time.Time) error
- func (this *Tx) PurgeReceipts(before time.Time) (int64, error)
- func (this *Tx) QueueRemoval(topic string, id string, at time.Time) error
- func (this *Tx) RecordElementError(instanceId string, run int, elementId string, message string, at time.Time) error
- func (this *Tx) RemoveEventDescriptions(deploymentId string, now time.Time) error
- func (this *Tx) RemoveModulesOfInstance(instanceId string) (int, error)
- func (this *Tx) RemoveResource(ref model.ResourceRef) (networkId string, err error)
- func (this *Tx) ReplaceEventDescriptions(deploymentId string, descriptions []model.EventDescription, groups []string, ...) error
- func (this *Tx) ReplaceReplicatedIncidents(instanceId string, run int, incidents []model.Incident) error
- func (this *Tx) ReplaceStartEvents(deploymentId string, events []StartEvent) error
- func (this *Tx) ResourceChecks(deploymentId string) (map[int]ResourceCheck, error)
- func (this *Tx) RetryModuleRemoval(moduleId string, next time.Time, message string) error
- func (this *Tx) RetryNotification(id string, due time.Time, message string) error
- func (this *Tx) RetryRemoval(topic string, id string, due time.Time, message string) error
- func (this *Tx) RunningVersions(deploymentId string) (result []int, err error)
- func (this *Tx) SaveJob(j Job) error
- func (this *Tx) SaveSchedule(s model.Schedule) error
- func (this *Tx) SaveSnapshot(instanceId string, seq int64, run int, at time.Time, state model.DebugState) error
- func (this *Tx) SaveToken(t Token) error
- func (this *Tx) SaveWatch(w Watch) error
- func (this *Tx) SetApplied(a Applied) error
- func (this *Tx) SetDeploymentDisabled(id string, disabled bool) error
- func (this *Tx) SetDesiredApplied(networkId string, kind string, id string, version int64, message string, ...) error
- func (this *Tx) SetGatewayOwner(owner string) (int64, error)
- func (this *Tx) SetInstanceInfo(id string, namespace string, name string, description string) error
- func (this *Tx) SetIoValue(userId string, v model.IoValue) error
- func (this *Tx) SetModuleCheck(id string, message string, at time.Time) error
- func (this *Tx) SetNetworkOwner(networkId string, owner string) (int64, error)
- func (this *Tx) SetOwner(kind model.Kind, id string, owner string) error
- func (this *Tx) SetResourceCheck(check ResourceCheck) error
- func (this *Tx) SetRestartStats(deploymentId string, stats RestartStats) error
- func (this *Tx) SetStartEventDue(deploymentId string, elementId string, due *time.Time) error
- func (this *Tx) SetStartVariables(instanceId string, variables map[string]any) error
- func (this *Tx) SetSubtaskResult(jobId string, subId string, value any) (bool, error)
- func (this *Tx) SetSyncPosition(name string, position int64) error
- func (this *Tx) SetUserSettings(settings model.UserSettings) error
- func (this *Tx) SetVariable(instanceId string, name string, value any, elementId string, at time.Time) error
- func (this *Tx) SnapshotAtOrBefore(instanceId string, seq int64) (result model.DebugState, found bool, err error)
- func (this *Tx) StaleNetworks(before time.Time) (result []string, err error)
- func (this *Tx) StalledInstances(before time.Time) (map[string]int, error)
- func (this *Tx) StorageRows() (map[string]int, error)
- func (this *Tx) SyncPosition(name string) (result int64, err error)
- func (this *Tx) TakeMessage(instanceId string, name string) (variables map[string]any, found bool, err error)
- func (this *Tx) TopActivityInstances(limit int) (result []ActivityCount, err error)
- func (this *Tx) TrimActivities(instanceId string, minSeq int64) error
- func (this *Tx) TrimChanges(before time.Time, limit int) (int64, error)
- func (this *Tx) TrimHistory(column string, value string, before time.Time) error
- func (this *Tx) TrimModelVersions(modelId string, keep int) error
- func (this *Tx) TrimOldestHistory(limit int) (int64, error)
- func (this *Tx) TrimSnapshots(instanceId string, activityMinSeq int64, keep int) error
- func (this *Tx) UpdateDeployment(d model.Deployment) error
- func (this *Tx) UpdateInstance(i Instance) error
- func (this *Tx) UpdateModel(m model.Model) error
- func (this *Tx) UpdateNamespace(ns model.Namespace, at time.Time) error
- func (this *Tx) UpdateNetwork(n Network) error
- func (this *Tx) UpdateRun(r model.Run) error
- func (this *Tx) UpdateWatch(id string, hash string, message string) error
- func (this *Tx) UpsertModule(m model.Module) error
- func (this *Tx) UpsertReplicatedInstance(networkId string, i model.Instance) error
- func (this *Tx) UsedBytes() (int64, error)
- func (this *Tx) UserDependents(userId string) (result []model.Dependent, err error)
- func (this *Tx) UserRetentionCaps() (result []model.UserSettings, err error)
- func (this *Tx) VariablesSize(instanceId string) (int, error)
- type Watch
Constants ¶
const ( SubscriptionMessage = "message" SubscriptionTimer = "timer" )
const ( // waits for execution JobPending = "pending" // claimed by an engine replica until lock_until JobRunning = "running" // the task type waits asynchronously for an answer until lock_until (TASK-00) JobWaiting = "waiting" )
const ChangesChannel = "automation_engine_changes"
ChangesChannel is the Postgres channel that announces changes of instances on commit; the payload is the instance id.
const PositionUpAcked = "up_acked"
PositionUpAcked is the position of the change stream of a gateway the cloud has taken.
Variables ¶
This section is empty.
Functions ¶
func IsDiskFull ¶
IsDiskFull reports a write that failed for lack of space (SQLITE_FULL, Postgres disk_full).
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a violated unique or primary key constraint.
Types ¶
type Access ¶
type Access struct {
Admin bool
Owner string
Ids []string
// deployments or instances of gateways the user holds rights on although the namespace does
// not share them, e.g. as the one who deployed or started them (FOG-11)
Gateway []string
}
Access restricts list queries to what the caller may see: everything for admins, otherwise own resources plus explicitly granted ids (filled from permissions-v2 in M2).
type ActivityCount ¶
type Change ¶
type Change struct {
Seq int64
InstanceId string
Namespace string
ActivitySeq int64
Deleted bool
Time time.Time
}
Change is an entry of the change stream (SYNC-03).
type Desired ¶
type Desired struct {
NetworkId string
Kind string
Id string
Version int64
Deleted bool
Spec json.RawMessage
AppliedVersion int64
Error string
AppliedAt time.Time
SentAt time.Time
UpdatedAt time.Time
}
Desired is the desired state of a resource of a gateway and how far the gateway applied it.
type DesiredCounts ¶
DesiredCounts are the resources of a network not applied yet and those that failed.
type GatewayResource ¶
type GatewayResource struct {
Kind model.ResourceKind
Id string
NetworkId string
}
GatewayResource is a deployment or instance that runs on a gateway.
type Instance ¶
type Instance struct {
model.Instance
ActivitySeq int64
ActivityMinSeq int64
// activity sequence and time of the latest history snapshot (DBG-14)
SnapshotSeq int64
SnapshotAt time.Time
}
Instance is the stored form of an instance with the counters of its activity log.
type Job ¶
type Job struct {
Id string
InstanceId string
Run int
TokenId string
ElementId string
TaskType string
Input map[string]any
State string
Attempt int
Retries int
Timeout time.Duration
DueAt time.Time
LockOwner string
LockUntil time.Time
LastError string
CreatedAt time.Time
}
Job executes a service task outside the transaction of the instance.
type ModuleRemoval ¶
type Network ¶
type Network struct {
Id string
EngineVersion string
Protocol int
Compatible bool
StartedAt time.Time
LastContact time.Time
// the latest position of the change stream of the gateway and the one the cloud took
Latest int64
Acked int64
Storage json.RawMessage
CreatedAt time.Time
}
Network is a gateway the cloud synchronises with (SYNC-12).
type Notification ¶
type Notification struct {
Id string
UserId string
Title string
Message string
Topic string
// of the resource the notification is about; empty for none, e.g. the storage budget
Namespace string
Attempts int
CreatedAt time.Time
}
Notification is a message to a user, sent after commit through the notifier (INC-02).
type Registration ¶
Registration is a resource whose rights still have to be written to permissions-v2.
type ResourceCheck ¶
type ResourceCheck struct {
DeploymentId string
Version int
Changed []model.ChangedResource
// import type id -> hash of its first seen content
Hashes map[string]string
CheckedAt time.Time
}
ResourceCheck is the stored result of the check of the resources of a deployment version.
type RestartStats ¶
RestartStats count automatic restarts of a deployment within the current window (INC-04).
type RetentionTarget ¶
RetentionTarget is a deployment as the retention pass sees it.
type StartEvent ¶
type StartEvent struct {
DeploymentId string
Version int
ElementId string
Kind string
MessageName string
DueAt *time.Time
// from the deployment
Namespace string
Owner string
}
StartEvent is a message or timer start event of the current version of a deployment.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists everything in one relational database, Postgres in the cloud and SQLite on gateways and in tests (OPS-02, FOG-03). Both share schema and queries.
func Open ¶
Open connects and applies pending migrations (OPS-03). For SQLite, dsn is a file path or a modernc.org/sqlite URI; pragmas for foreign keys, immediate transactions and incremental vacuum (LONG-06) are added.
func (*Store) DisablePermissionRemovals ¶
func (this *Store) DisablePermissionRemovals()
DisablePermissionRemovals stops queueing rights for removal from permissions-v2, for an engine without permissions-v2.
func (*Store) Full ¶
Full reports whether the last write failed for lack of space; a successful write clears it.
func (*Store) SetMaxOpenConns ¶ added in v0.1.0
SetMaxOpenConns limits the connections of the process to the database; further requests wait for a free one.
type Subscription ¶
type Subscription struct {
Id string
InstanceId string
Run int
TokenId string
ElementId string
Kind string
MessageName string
DueAt *time.Time
// subscriptions of an event-based gateway share a group; the first trigger cancels the others
GroupId string
Definition string
CreatedAt time.Time
// from the instance
Owner string
Namespace string
}
Subscription waits for a message or a timer on behalf of a token.
type Subtask ¶
type Subtask struct {
JobId string
SubId string
Position int
Command json.RawMessage
TaskInfo json.RawMessage
HasResult bool
Result any
Tries int
LastTry time.Time
}
Subtask is the command for one device and service of a device command (TASK-06); it replaces the sub-task state the external-task-worker kept in memcached.
type Token ¶
type Token struct {
Id string
InstanceId string
Run int
ElementId string
State TokenState
ArrivedVia string
Locals map[string]any
CreatedAt time.Time
}
Token marks an active position in a run; it is deleted when it ends (LONG-02).
type TokenState ¶
type TokenState string
const ( // the token is about to execute its element TokenReady TokenState = "ready" // the token waits for a timer, a message or a job TokenWaiting TokenState = "waiting" // the token waits at a joining gateway TokenJoining TokenState = "joining" )
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
func (*Tx) ActivitySeqAt ¶
ActivitySeqAt is the sequence of the last activity entry at or before a time; false if there is none.
func (*Tx) AllDeployments ¶
AllDeployments lists the deployments of all namespaces by id, those after the id after.
func (*Tx) BufferMessage ¶
func (this *Tx) BufferMessage(instanceId string, name string, variables map[string]any, at time.Time) error
BufferMessage keeps a message for an instance until it waits for it (SMS-04); a newer one with the same name replaces it.
func (*Tx) ChangesAfter ¶
ChangesAfter lists entries of the change stream after seq in order of their sequence.
func (*Tx) ChildInstances ¶
ChildInstances lists the maintenance procedures of an instance (SMS-13).
func (*Tx) ClaimDueWatches ¶
ClaimDueWatches returns the watches due at now and moves their next check one interval past now, so that each is checked once per interval by one replica.
func (*Tx) ClearRuntime ¶
ClearRuntime removes all runtime state of an instance, e.g. when its run ends.
func (*Tx) ConsecutiveIncidentRuns ¶
ConsecutiveIncidentRuns counts the runs that ended with an incident, from the latest backwards.
func (*Tx) CountElementPass ¶
CountElementPass increments the pass counter of an element (LONG-04).
func (*Tx) CountIoValues ¶
CountIoValues counts the values of a user that no instance holds, for the limit (LONG-11).
func (*Tx) CountSubtaskTry ¶
func (*Tx) DatabaseBytes ¶
DatabaseBytes is the size of the database.
func (*Tx) DeleteDeployment ¶
DeleteDeployment removes the deployment with all versions, instances, history, incidents and start events in one statement through ON DELETE CASCADE (DEP-11). Registered rights of the deployment and its instances are queued for removal.
func (*Tx) DeleteFinishedInstances ¶
func (this *Tx) DeleteFinishedInstances(column string, value string, before time.Time, limit int) (int64, error)
DeleteFinishedInstances removes up to limit instances whose run ended before the cutoff, selected by column (deployment_id or owner); their history goes with them (HIST-04).
func (*Tx) DeleteInstance ¶
func (*Tx) DeleteModel ¶
func (*Tx) DeleteModule ¶
DeleteModule removes a module and queues the removal of its resource (SMS-06).
func (*Tx) DeleteNamespace ¶
func (*Tx) DeleteNetwork ¶
DeleteNetwork removes a network with its deployments, instances and desired state (SYNC-07). Instances and deployments go the way of every deletion, so that their rights are removed from permissions-v2 and the change stream reports the deleted instances.
func (*Tx) DeleteNotification ¶
func (*Tx) DeleteOwned ¶
DeleteOwned deletes everything a user owns, in all namespaces (SEC-08): instances, deployments with all their instances, models and the user's settings. Rights are queued for removal from permissions-v2.
Modules are not queued for removal: user-management removes the user's resources in the other services itself, and a token of the deleted user would fail every attempt.
func (*Tx) DeleteSchedule ¶
func (*Tx) DeleteSubscriptionsOfToken ¶
func (*Tx) DeleteToken ¶
func (*Tx) DeleteUserSettings ¶
func (*Tx) DeleteVariables ¶
func (*Tx) DeleteWatch ¶
func (*Tx) DeploymentVersionCreated ¶
func (*Tx) DeploymentsAfter ¶
func (this *Tx) DeploymentsAfter(afterId string, limit int) (result []RetentionTarget, err error)
DeploymentsAfter pages through all deployments by id, for passes in small steps (LONG-05).
func (*Tx) DeploymentsOfDeviceGroup ¶
DeploymentsOfDeviceGroup lists deployments whose events depend on a device group (DEP-08).
func (*Tx) DeploymentsOfOthers ¶ added in v0.16.1
DeploymentsOfOthers counts the deployments of owners other than owner that carry the id as their own or as the id of their model, e.g. the releases of a design (SNRGY-4993).
func (*Tx) Desire ¶
func (this *Tx) Desire(networkId string, kind string, id string, deleted bool, spec any, now time.Time) (version int64, err error)
Desire sets the desired state of a resource of a gateway with the next version; it goes out with the next pass of the reconciler (SYNC-01). The spec is JSON of the resource content.
func (*Tx) DesiredBacklog ¶
func (this *Tx) DesiredBacklog() (map[string]DesiredCounts, error)
DesiredBacklog counts per network what its gateway has not applied (SYNC-12).
func (*Tx) DeviceGroupsOfDeployment ¶
DeviceGroupsOfDeployment lists the device groups the events of a deployment depend on.
func (*Tx) DueDesired ¶
DueDesired lists resources the gateway has not applied in their version and that were not sent since before, of networks in contact since contactAfter (SYNC-08).
func (*Tx) DueModuleRemovals ¶
func (*Tx) DueNotifications ¶
func (*Tx) DueRemovals ¶
func (*Tx) DueRestarts ¶
DueRestarts lists instances whose automatic restart is due. Instances of gateways are left out: their gateway restarts them, the cloud only shows the planned time (FOG-07).
func (*Tx) DueSchedules ¶
func (*Tx) DueStartTimers ¶
func (*Tx) EnsureSubtasks ¶
EnsureSubtasks stores the sub-tasks of a job; results of existing ones are kept.
func (*Tx) EventDescriptionsSince ¶
func (this *Tx) EventDescriptionsSince(revision int64) (result []model.EventDescription, removed []string, latest int64, err error)
EventDescriptionsSince returns descriptions and removed ids with a revision above the given one, and the highest revision; revision 0 loads everything.
func (*Tx) FinishModuleRemoval ¶
func (*Tx) ForgetEndedInstance ¶
ForgetEndedInstance removes the start or stop of an instance the gateway reported as ended; both are done, and the gateway forgets them once the instance is gone there.
func (*Tx) GatewayDeploymentIds ¶
GatewayDeploymentIds lists the deployments of a namespace that run on gateways.
func (*Tx) GetApplied ¶
GetApplied reads the applied version of a resource; found is false if none was applied.
func (*Tx) GetDeployment ¶
func (*Tx) GetDeploymentVersion ¶
func (*Tx) GetDesired ¶
GetDesired reads the desired state of a resource; found is false if there is none.
func (*Tx) GetIncidentHandling ¶
func (*Tx) GetInstance ¶
GetInstance reads an instance; with lock, the row stays locked until the transaction ends, which serializes all state transitions of the instance (RUN-08).
func (*Tx) GetIoValue ¶
GetIoValue returns the value of a key; ok is false if the key is not set.
func (*Tx) GetModelVersion ¶
func (*Tx) GetNetwork ¶
GetNetwork reads a network; found is false if it never reported.
func (*Tx) GetRestartStats ¶
func (this *Tx) GetRestartStats(deploymentId string) (result RestartStats, err error)
func (*Tx) GetStartEvent ¶
func (this *Tx) GetStartEvent(deploymentId string, elementId string) (StartEvent, error)
func (*Tx) GetSubscription ¶
func (this *Tx) GetSubscription(id string) (*Subscription, error)
func (*Tx) GetUserSettings ¶
func (this *Tx) GetUserSettings(userId string) (result model.UserSettings, err error)
func (*Tx) GetVariables ¶
func (*Tx) InitSyncPosition ¶
InitSyncPosition sets a position to 0 unless it is set.
func (*Tx) InsertActivity ¶
InsertActivity appends an entry to the activity log; the caller holds the instance lock and passes the sequence number taken from the instance.
func (*Tx) InsertDeployment ¶
func (this *Tx) InsertDeployment(d model.Deployment) error
func (*Tx) InsertDeploymentVersion ¶
func (this *Tx) InsertDeploymentVersion(v model.DeploymentVersion) error
func (*Tx) InsertInstance ¶
func (*Tx) InsertModelVersion ¶
func (this *Tx) InsertModelVersion(v model.ModelVersion) error
func (*Tx) InsertNamespace ¶
InsertNamespace stores a namespace unless one with the name exists; it reports whether it did.
func (*Tx) InsertNotification ¶
func (this *Tx) InsertNotification(n Notification) error
func (*Tx) InsertReceipt ¶
InsertReceipt records that a message has been correlated with a target and reports whether it is new (EVT-05).
func (*Tx) InsertSubscription ¶
func (this *Tx) InsertSubscription(s Subscription) error
func (*Tx) InstanceIds ¶
InstanceIds lists the ids of all instances, for a snapshot of a gateway (LONG-10).
func (*Tx) InstanceIdsOfDeployment ¶
func (*Tx) InstancesPerVersion ¶
InstancesPerVersion counts the instances of a deployment by the version they run on.
func (*Tx) JobCandidates ¶
JobCandidates lists pending jobs that are due and claimed jobs whose lock expired.
func (*Tx) LatestChangeSeq ¶
LatestChangeSeq is the sequence of the newest entry of the change stream, 0 if it is empty.
func (*Tx) ListActivities ¶
func (*Tx) ListApplied ¶
func (*Tx) ListDeploymentVersions ¶
func (this *Tx) ListDeploymentVersions(deploymentId string, page model.PageOptions) (result model.Page[model.DeploymentVersion], err error)
ListDeploymentVersions returns versions without XML and SVG, newest first.
func (*Tx) ListDeployments ¶
func (this *Tx) ListDeployments(namespace string, options model.DeploymentListOptions, access Access) (result model.Page[model.Deployment], err error)
func (*Tx) ListDesired ¶
ListDesired lists the desired state of a network, of one kind if kind is set.
func (*Tx) ListElementStats ¶
func (*Tx) ListEventDescriptions ¶
func (this *Tx) ListEventDescriptions(deploymentId string) (result []model.EventDescription, err error)
func (*Tx) ListIncidents ¶
func (*Tx) ListInstances ¶
func (*Tx) ListIoValues ¶
func (this *Tx) ListIoValues(userId string, deploymentId string, instanceId string, sort string) (result []model.IoValue, err error)
ListIoValues lists the values of a user filtered by deployment and instance; the key filter is applied by the caller, SQLite has no regular expressions.
func (*Tx) ListModelVersions ¶
func (this *Tx) ListModelVersions(modelId string, page model.PageOptions) (result model.Page[model.ModelVersion], err error)
ListModelVersions returns versions without XML and SVG, newest first.
func (*Tx) ListModels ¶
func (*Tx) ListModules ¶
func (this *Tx) ListModules(namespace string, options model.ModuleListOptions, access Access) (result model.Page[model.Module], err error)
ListModules lists the modules of the instances of a namespace the access allows (SMS-12).
func (*Tx) ListNetworks ¶
ListNetworks reads the given networks, all if ids is nil.
func (*Tx) ListSchedules ¶
func (*Tx) ListSubscriptions ¶
func (this *Tx) ListSubscriptions(instanceId string) ([]Subscription, error)
func (*Tx) LockNetwork ¶
LockNetwork reads a network and locks it until the end of the transaction, so that messages of one gateway are taken one after the other by any replica; it creates the network on its first message (SYNC-10).
func (*Tx) LowerDesiredApplied ¶
func (this *Tx) LowerDesiredApplied(networkId string, kind string, id string, version int64, message string) error
LowerDesiredApplied takes back what a gateway acknowledged but no longer reports, e.g. after it lost its database: the applied version falls to the reported one and the resource is due again. A gateway that reports as much or more changes nothing.
func (*Tx) MarkDesiredSent ¶
func (this *Tx) MarkDesiredSent(networkId string, kind string, id string, version int64, at time.Time) error
MarkDesiredSent remembers that a version went out; a newer desired version resets it.
func (*Tx) MarkNamespaceUnregistered ¶
MarkNamespaceUnregistered schedules all resources of a kind in a namespace for registration, e.g. when a level becomes registered.
func (*Tx) MarkRegistered ¶
MarkRegistered records a registration done for owner; false if the resource is gone or its owner changed meanwhile, then the registration has to be repeated or undone.
func (*Tx) MarkUnregistered ¶
MarkUnregistered schedules a resource for (re)registration, e.g. after an owner change.
func (*Tx) MessageStartEvents ¶
func (this *Tx) MessageStartEvents(messageName string, owner string) ([]StartEvent, error)
MessageStartEvents finds message start events by message name, optionally of one owner.
func (*Tx) MessageSubscriptions ¶
func (this *Tx) MessageSubscriptions(messageName string, instanceId string, owner string) ([]Subscription, error)
MessageSubscriptions finds waiting message events, optionally of one instance or owner.
func (*Tx) ModelsAfter ¶
func (*Tx) ModuleErrors ¶
ModuleErrors returns the first module error per instance, for the status (SMS-11).
func (*Tx) ModulesOfInstance ¶
func (this *Tx) ModulesOfInstance(instanceId string, key string, moduleType string) ([]model.Module, error)
ModulesOfInstance lists the modules of an instance, optionally only those with a key and type.
func (*Tx) ModulesToCheck ¶
func (this *Tx) ModulesToCheck(moduleType string, before time.Time, limit int) ([]model.Module, error)
ModulesToCheck lists modules of a type whose last health check is older than before (SMS-11).
func (*Tx) NamespaceInUse ¶
NamespaceInUse reports whether models, deployments or instances belong to the namespace.
func (*Tx) NetworkInstanceIds ¶
NetworkInstanceIds lists the instances of a gateway, for its snapshot (LONG-10).
func (*Tx) NetworksWithDeployments ¶ added in v0.16.0
NetworksWithDeployments lists the networks that have deployments.
func (*Tx) OldestChangeSeq ¶
OldestChangeSeq is the sequence of the oldest entry of the change stream, 0 if it is empty; a position before it cannot be continued, the entries in between are purged.
func (*Tx) OldestSnapshotSeq ¶
OldestSnapshotSeq is the sequence of the oldest snapshot of an instance; false if there is none.
func (*Tx) OwnedCounts ¶
OwnedCounts counts the resources of a user per permissions-v2 topic name.
func (*Tx) OwnedOnGateways ¶
func (this *Tx) OwnedOnGateways(userId string) (result []GatewayResource, err error)
OwnedOnGateways lists the deployments and instances of a user that run on gateways, which DeleteOwned removes only in the cloud (SEC-08). Instances of the user's deployments are left out: the gateway deletes them with their deployment.
func (*Tx) Owner ¶
func (this *Tx) Owner(kind model.Kind, id string) (owner string, namespace string, ok bool, err error)
Owner returns the owner of a resource; ok is false if it does not exist.
func (*Tx) PendingRegistrations ¶
PendingRegistrations lists resources not yet registered in permissions-v2.
func (*Tx) PruneAppliedInstances ¶
PruneAppliedInstances forgets instances applied without error that are gone; the cloud forgets them when they end, so that neither side grows with every start.
func (*Tx) PurgeChanges ¶
PurgeChanges removes entries older than before, at most limit at a time (LONG-05).
func (*Tx) RecordElementError ¶
func (*Tx) RemoveEventDescriptions ¶
RemoveEventDescriptions runs before a deployment is deleted.
func (*Tx) RemoveModulesOfInstance ¶
RemoveModulesOfInstance removes the modules and maintenance procedures of an instance, e.g. before a new run; the resources of the modules are queued for removal. It returns the number of removed modules.
func (*Tx) RemoveResource ¶
func (this *Tx) RemoveResource(ref model.ResourceRef) (networkId string, err error)
RemoveResource removes a resource of the engine a module refers to; a missing one counts as removed. The namespace must match, so that a module cannot reach into other namespaces. For a deployment or instance of a gateway, it returns the network id: only the cloud rows are removed, the caller desires the deletion on the gateway.
func (*Tx) ReplaceEventDescriptions ¶
func (this *Tx) ReplaceEventDescriptions(deploymentId string, descriptions []model.EventDescription, groups []string, now time.Time) error
ReplaceEventDescriptions sets the descriptions and device groups of a deployment.
func (*Tx) ReplaceReplicatedIncidents ¶
func (this *Tx) ReplaceReplicatedIncidents(instanceId string, run int, incidents []model.Incident) error
ReplaceReplicatedIncidents keeps the incidents of the current run as the gateway reported them.
func (*Tx) ReplaceStartEvents ¶
func (this *Tx) ReplaceStartEvents(deploymentId string, events []StartEvent) error
func (*Tx) ResourceChecks ¶
func (this *Tx) ResourceChecks(deploymentId string) (map[int]ResourceCheck, error)
func (*Tx) RetryModuleRemoval ¶
func (*Tx) RetryNotification ¶
func (*Tx) RetryRemoval ¶
func (*Tx) RunningVersions ¶
RunningVersions returns the deployment versions that still have running instances.
func (*Tx) SaveSnapshot ¶
func (this *Tx) SaveSnapshot(instanceId string, seq int64, run int, at time.Time, state model.DebugState) error
SaveSnapshot stores a full state of an instance at an activity sequence (DBG-14).
func (*Tx) SaveWatch ¶
SaveWatch creates or replaces a watch; a replaced one starts over with a new baseline.
func (*Tx) SetApplied ¶
func (*Tx) SetDeploymentDisabled ¶
SetDeploymentDisabled switches a deployment off or on; updates keep the state (DEP-12).
func (*Tx) SetDesiredApplied ¶
func (this *Tx) SetDesiredApplied(networkId string, kind string, id string, version int64, message string, at time.Time) error
SetDesiredApplied records what the gateway applied; an older report changes nothing. A deletion the gateway applied is forgotten.
func (*Tx) SetGatewayOwner ¶ added in v0.16.0
SetGatewayOwner gives every deployment, event description and instance on a gateway the owner of its network (FOG-11). Changed instances enter the change stream, so that the cloud takes the owner over. It returns the number of changed deployments and instances.
func (*Tx) SetInstanceInfo ¶
SetInstanceInfo changes name and description of an instance.
func (*Tx) SetIoValue ¶
SetIoValue stores a value; deployment and instance ids bind it to their lifetime (IO-03).
func (*Tx) SetModuleCheck ¶
SetModuleCheck stores the result of a health check; an empty message clears the error.
func (*Tx) SetNetworkOwner ¶ added in v0.16.0
SetNetworkOwner gives the deployments of a network, their event descriptions and the instances of the network the owner of the network (FOG-11); the rights of the owner are registered again where it changed. It returns the number of changed deployments and instances.
func (*Tx) SetOwner ¶
SetOwner changes the owner and schedules the registration of the new owner's rights (SEC-11).
func (*Tx) SetResourceCheck ¶
func (this *Tx) SetResourceCheck(check ResourceCheck) error
func (*Tx) SetRestartStats ¶
func (this *Tx) SetRestartStats(deploymentId string, stats RestartStats) error
func (*Tx) SetStartEventDue ¶
func (*Tx) SetStartVariables ¶
SetStartVariables replaces the stored start variables, e.g. after a parameter change (SMS-09).
func (*Tx) SetSubtaskResult ¶
SetSubtaskResult stores the result of a sub-task; false if the sub-task does not exist, e.g. because its job has already been completed.
func (*Tx) SetUserSettings ¶
func (this *Tx) SetUserSettings(settings model.UserSettings) error
func (*Tx) SetVariable ¶
func (this *Tx) SetVariable(instanceId string, name string, value any, elementId string, at time.Time) error
SetVariable stores a JSON value; size is the length of its JSON form.
func (*Tx) SnapshotAtOrBefore ¶
func (this *Tx) SnapshotAtOrBefore(instanceId string, seq int64) (result model.DebugState, found bool, err error)
SnapshotAtOrBefore returns the latest snapshot with a sequence up to seq; false if there is none.
func (*Tx) StaleNetworks ¶
StaleNetworks lists networks without contact since before (SYNC-07).
func (*Tx) StalledInstances ¶
StalledInstances counts running instances per namespace without element change since before (LONG-13).
func (*Tx) StorageRows ¶
StorageRows counts rows per table, for the storage metrics (LONG-14).
func (*Tx) SyncPosition ¶
SyncPosition reads a position of the synchronisation, 0 if it was never set.
func (*Tx) TakeMessage ¶
func (this *Tx) TakeMessage(instanceId string, name string) (variables map[string]any, found bool, err error)
TakeMessage removes and returns a buffered message; false if there is none.
func (*Tx) TopActivityInstances ¶
func (this *Tx) TopActivityInstances(limit int) (result []ActivityCount, err error)
TopActivityInstances lists the instances with the most activity entries (LONG-14); the count follows from the sequence numbers, because the log is trimmed from its beginning.
func (*Tx) TrimActivities ¶
TrimActivities removes entries with a sequence number below minSeq (LONG-03).
func (*Tx) TrimChanges ¶
TrimChanges removes entries of the change stream older than before, at most limit at a time (LONG-05). On a gateway, the entries after the position the cloud acknowledged are what keeps an instance from retention and budget (unsynced), however long the gateway is offline: of those, only entries followed by a later one of the same instance are removed. The change stream then holds at most one entry per instance changed since the acknowledgement, and the cloud gets the latest state of each, as it would from a fold of the batch (LONG-09, LONG-10). The trade-off: while offline, instances that ended stay with their runtime rows and the budget can only trim their history; a gateway that ends more instances offline than its budget holds fills up instead of losing ends the cloud has not seen (LONG-07).
func (*Tx) TrimHistory ¶
TrimHistory removes history older than the cutoff from instances that are kept, in particular from running instances, whose history must not grow with their runtime (HIST-06). column selects the instances by deployment_id or owner.
func (*Tx) TrimModelVersions ¶
TrimModelVersions keeps the newest versions of a model and every version a deployment refers to (MOD-07).
func (*Tx) TrimOldestHistory ¶
TrimOldestHistory removes the oldest history beyond any retention, when the storage budget is near (LONG-07): finished instances first, then the oldest activity entries and incidents of all instances. Runtime state stays; instances with modules stay, as with the retention, and on a gateway instances whose end the cloud has not taken. It returns the number of removed rows; 0 means there is no history left.
func (*Tx) TrimSnapshots ¶
TrimSnapshots removes snapshots that cannot start a reconstruction anymore, because the activities after them were evicted, and keeps at most keep of the others.
func (*Tx) UpdateDeployment ¶
func (this *Tx) UpdateDeployment(d model.Deployment) error
func (*Tx) UpdateInstance ¶
func (*Tx) UpdateNamespace ¶
func (*Tx) UpdateNetwork ¶
func (*Tx) UpdateWatch ¶
UpdateWatch stores the result of a check.
func (*Tx) UpsertModule ¶
UpsertModule writes a module; an existing one with the same id is replaced, created_at stays. A written module counts as checked when it was written: its resource may still be starting, a pipeline for instance, and the workers checked a new module only at their next pass (SMS-11). The error of a replaced resource goes with it.
func (*Tx) UpsertReplicatedInstance ¶
UpsertReplicatedInstance writes the state of an instance as its gateway reported it; name and description belong to the cloud and stay; an instance of a deployment the cloud no longer has is skipped. restart_at only shows when the gateway restarts it; DueRestarts leaves instances of gateways out (FOG-07). The owner is that of the deployment, the owner of the network, also when a gateway that does not know it yet reports another (FOG-11).
func (*Tx) UsedBytes ¶
UsedBytes is the size of the data; free pages of SQLite are reused and not counted (LONG-07).
func (*Tx) UserDependents ¶
UserDependents lists resources of other owners that would be deleted with the user's resources (SEC-13): instances of others on deployments the user owns. Deployments of others based on the user's models are not dependents, they keep their copy of the BPMN (MOD-08).
func (*Tx) UserRetentionCaps ¶
func (this *Tx) UserRetentionCaps() (result []model.UserSettings, err error)
UserRetentionCaps lists users with a retention limit.
type Watch ¶
type Watch struct {
Id string
InstanceId string
Namespace string
Owner string
Procedure string
Parameters map[string]any
Request model.WatchRequest
HashType string
Interval time.Duration
LastHash string
NextAt time.Time
LastError string
CreatedAt time.Time
}
Watch is a periodic check of the watcher task type (TASK-27).