store

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 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

Index

Constants

View Source
const (
	SubscriptionMessage = "message"
	SubscriptionTimer   = "timer"
)
View Source
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"
)
View Source
const ChangesChannel = "automation_engine_changes"

ChangesChannel is the Postgres channel that announces changes of instances on commit; the payload is the instance id.

View Source
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

func IsDiskFull(err error) bool

IsDiskFull reports a write that failed for lack of space (SQLITE_FULL, Postgres disk_full).

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err is a violated unique or primary key constraint.

Types

type Access

type Access struct {
	Admin bool
	Owner string
	Ids   []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 ActivityCount struct {
	InstanceId string
	Namespace  string
	Count      int64
}

type Applied

type Applied struct {
	Kind    string
	Id      string
	Version int64
	Error   string
	At      time.Time
}

Applied is a desired resource of the cloud as a gateway applied it (SYNC-13).

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

type DesiredCounts struct {
	Pending int
	Failed  int
}

DesiredCounts are the resources of a network not applied yet and those that failed.

type Dialect

type Dialect string
const (
	Postgres Dialect = "postgres"
	SQLite   Dialect = "sqlite"
)

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 ModuleRemoval struct {
	ModuleId   string
	Namespace  string
	Owner      string
	ModuleType string
	DeleteInfo model.ModuleDeleteInfo
	Attempts   int
}

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

type Registration struct {
	Kind      model.Kind
	Id        string
	Namespace string
	Owner     string
}

Registration is a resource whose rights still have to be written to permissions-v2.

type Removal

type Removal struct {
	Topic      string
	ResourceId string
	Attempts   int
}

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

type RestartStats struct {
	WindowStart time.Time
	Count       int
	FaultySince *time.Time
}

RestartStats count automatic restarts of a deployment within the current window (INC-04).

type RetentionTarget

type RetentionTarget struct {
	Id            string
	Namespace     string
	RetentionDays int
}

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

func Open(ctx context.Context, dialect Dialect, dsn string) (*Store, error)

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) Close

func (this *Store) Close() error

func (*Store) Dialect

func (this *Store) Dialect() Dialect

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

func (this *Store) Full() bool

Full reports whether the last write failed for lack of space; a successful write clears it.

func (*Store) Ping

func (this *Store) Ping(ctx context.Context) error

Ping checks that the database is reachable (readiness, OPS-04).

func (*Store) SetMaxOpenConns added in v0.1.0

func (this *Store) SetMaxOpenConns(n int)

SetMaxOpenConns limits the connections of the process to the database; further requests wait for a free one.

func (*Store) Tx

func (this *Store) Tx(ctx context.Context, fn func(tx *Tx) error) (err error)

Tx runs fn in a transaction; it is committed if fn returns nil.

func (*Store) Vacuum

func (this *Store) Vacuum(ctx context.Context, pages int) error

Vacuum returns freed pages to the file system in small steps (LONG-06); a no-op for Postgres.

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

func (this *Tx) ActivitySeqAt(instanceId string, at time.Time) (seq int64, found bool, err error)

ActivitySeqAt is the sequence of the last activity entry at or before a time; false if there is none.

func (*Tx) AllDeployments

func (this *Tx) AllDeployments(after string, limit int) ([]model.Deployment, error)

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

func (this *Tx) ChangesAfter(seq int64, limit int) (result []Change, err error)

ChangesAfter lists entries of the change stream after seq in order of their sequence.

func (*Tx) ChildInstances

func (this *Tx) ChildInstances(parentId string) (result []string, err error)

ChildInstances lists the maintenance procedures of an instance (SMS-13).

func (*Tx) ClaimDueWatches

func (this *Tx) ClaimDueWatches(now time.Time, limit int) (result []Watch, err error)

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

func (this *Tx) ClearRuntime(instanceId string) error

ClearRuntime removes all runtime state of an instance, e.g. when its run ends.

func (*Tx) ConsecutiveIncidentRuns

func (this *Tx) ConsecutiveIncidentRuns(instanceId string) (int, error)

ConsecutiveIncidentRuns counts the runs that ended with an incident, from the latest backwards.

func (*Tx) CountElementPass

func (this *Tx) CountElementPass(instanceId string, run int, elementId string, at time.Time) error

CountElementPass increments the pass counter of an element (LONG-04).

func (*Tx) CountIoValues

func (this *Tx) CountIoValues(userId string) (int, error)

CountIoValues counts the values of a user that no instance holds, for the limit (LONG-11).

func (*Tx) CountJobs

func (this *Tx) CountJobs(instanceId string) (int, error)

func (*Tx) CountSubtaskTry

func (this *Tx) CountSubtaskTry(jobId string, subId string, at time.Time) error

func (*Tx) DatabaseBytes

func (this *Tx) DatabaseBytes() (int64, error)

DatabaseBytes is the size of the database.

func (*Tx) DeleteDeployment

func (this *Tx) DeleteDeployment(id string) error

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 (this *Tx) DeleteInstance(id string) error

func (*Tx) DeleteIoValue

func (this *Tx) DeleteIoValue(userId string, key string) error

func (*Tx) DeleteJob

func (this *Tx) DeleteJob(id string) error

func (*Tx) DeleteModel

func (this *Tx) DeleteModel(id string) error

func (*Tx) DeleteModule

func (this *Tx) DeleteModule(id string) error

DeleteModule removes a module and queues the removal of its resource (SMS-06).

func (*Tx) DeleteNamespace

func (this *Tx) DeleteNamespace(name string) error

func (*Tx) DeleteNetwork

func (this *Tx) DeleteNetwork(id string) error

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 (this *Tx) DeleteNotification(id string) error

func (*Tx) DeleteOwned

func (this *Tx) DeleteOwned(userId string) error

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) DeleteRemoval

func (this *Tx) DeleteRemoval(topic string, id string) error

func (*Tx) DeleteSchedule

func (this *Tx) DeleteSchedule(id string) error

func (*Tx) DeleteSubscriptionsOfToken

func (this *Tx) DeleteSubscriptionsOfToken(tokenId string) error

func (*Tx) DeleteToken

func (this *Tx) DeleteToken(id string) error

func (*Tx) DeleteUserSettings

func (this *Tx) DeleteUserSettings(userId string) error

func (*Tx) DeleteVariable

func (this *Tx) DeleteVariable(instanceId string, name string) error

func (*Tx) DeleteVariables

func (this *Tx) DeleteVariables(instanceId string) error

func (*Tx) DeleteWatch

func (this *Tx) DeleteWatch(id string) error

func (*Tx) DeploymentVersionCreated

func (this *Tx) DeploymentVersionCreated(deploymentId string, version int) (time.Time, error)

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

func (this *Tx) DeploymentsOfDeviceGroup(groupId string) (result []string, err error)

DeploymentsOfDeviceGroup lists deployments whose events depend on a device group (DEP-08).

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

func (this *Tx) DeviceGroupsOfDeployment(deploymentId string) (result []string, err error)

DeviceGroupsOfDeployment lists the device groups the events of a deployment depend on.

func (*Tx) DueDesired

func (this *Tx) DueDesired(before time.Time, contactAfter time.Time, limit int) ([]Desired, error)

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 (this *Tx) DueModuleRemovals(now time.Time, limit int) (result []ModuleRemoval, err error)

func (*Tx) DueNotifications

func (this *Tx) DueNotifications(now time.Time, limit int) (result []Notification, err error)

func (*Tx) DueRemovals

func (this *Tx) DueRemovals(now time.Time, limit int) (result []Removal, err error)

func (*Tx) DueRestarts

func (this *Tx) DueRestarts(now time.Time, limit int) (result []string, err error)

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 (this *Tx) DueSchedules(now time.Time, limit int) (result []model.Schedule, err error)

func (*Tx) DueStartTimers

func (this *Tx) DueStartTimers(now time.Time, limit int) ([]StartEvent, error)

func (*Tx) DueTimers

func (this *Tx) DueTimers(now time.Time, limit int) ([]Subscription, error)

func (*Tx) EnsureSubtasks

func (this *Tx) EnsureSubtasks(subtasks []Subtask) error

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 (this *Tx) FinishModuleRemoval(moduleId string) error

func (*Tx) ForgetEndedInstance

func (this *Tx) ForgetEndedInstance(networkId string, id string) error

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

func (this *Tx) GatewayDeploymentIds(namespace string) (result []string, err error)

GatewayDeploymentIds lists the deployments of a namespace that run on gateways.

func (*Tx) GetApplied

func (this *Tx) GetApplied(kind string, id string) (result Applied, found bool, err error)

GetApplied reads the applied version of a resource; found is false if none was applied.

func (*Tx) GetDeployment

func (this *Tx) GetDeployment(id string, lock bool) (model.Deployment, error)

func (*Tx) GetDeploymentVersion

func (this *Tx) GetDeploymentVersion(deploymentId string, version int) (v model.DeploymentVersion, err error)

func (*Tx) GetDesired

func (this *Tx) GetDesired(networkId string, kind string, id string) (Desired, bool, error)

GetDesired reads the desired state of a resource; found is false if there is none.

func (*Tx) GetIncidentHandling

func (this *Tx) GetIncidentHandling(deploymentId string, version int) (result model.IncidentHandling, err error)

func (*Tx) GetInstance

func (this *Tx) GetInstance(id string, lock bool) (Instance, error)

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

func (this *Tx) GetIoValue(userId string, key string) (result model.IoValue, ok bool, err error)

GetIoValue returns the value of a key; ok is false if the key is not set.

func (*Tx) GetJob

func (this *Tx) GetJob(id string) (*Job, error)

func (*Tx) GetModel

func (this *Tx) GetModel(id string, lock bool) (model.Model, error)

func (*Tx) GetModelVersion

func (this *Tx) GetModelVersion(modelId string, version int) (v model.ModelVersion, err error)

func (*Tx) GetModule

func (this *Tx) GetModule(id string) (model.Module, error)

func (*Tx) GetNetwork

func (this *Tx) GetNetwork(id string) (Network, bool, error)

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) GetRun

func (this *Tx) GetRun(instanceId string, run int) (r model.Run, err error)

func (*Tx) GetSchedule

func (this *Tx) GetSchedule(id string) (model.Schedule, 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 (this *Tx) GetVariables(instanceId string) (result []model.Variable, err error)

func (*Tx) HasReceipt

func (this *Tx) HasReceipt(messageId string, target string) (bool, error)

func (*Tx) InitSyncPosition

func (this *Tx) InitSyncPosition(name string) error

InitSyncPosition sets a position to 0 unless it is set.

func (*Tx) InsertActivity

func (this *Tx) InsertActivity(a model.Activity) error

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) InsertIncident

func (this *Tx) InsertIncident(i model.Incident) error

func (*Tx) InsertInstance

func (this *Tx) InsertInstance(i Instance) error

func (*Tx) InsertModel

func (this *Tx) InsertModel(m model.Model) error

func (*Tx) InsertModelVersion

func (this *Tx) InsertModelVersion(v model.ModelVersion) error

func (*Tx) InsertNamespace

func (this *Tx) InsertNamespace(ns model.Namespace, at time.Time) (bool, error)

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

func (this *Tx) InsertReceipt(messageId string, target string, at time.Time) (bool, error)

InsertReceipt records that a message has been correlated with a target and reports whether it is new (EVT-05).

func (*Tx) InsertRun

func (this *Tx) InsertRun(r model.Run) error

func (*Tx) InsertSubscription

func (this *Tx) InsertSubscription(s Subscription) error

func (*Tx) InstanceIds

func (this *Tx) InstanceIds() (result []string, err error)

InstanceIds lists the ids of all instances, for a snapshot of a gateway (LONG-10).

func (*Tx) InstanceIdsOfDeployment

func (this *Tx) InstanceIdsOfDeployment(deploymentId string, state model.InstanceState) (result []string, err error)

func (*Tx) InstancesPerVersion

func (this *Tx) InstancesPerVersion(deploymentId string) (map[int]int, error)

InstancesPerVersion counts the instances of a deployment by the version they run on.

func (*Tx) JobCandidates

func (this *Tx) JobCandidates(now time.Time, limit int) (result []Job, err error)

JobCandidates lists pending jobs that are due and claimed jobs whose lock expired.

func (*Tx) JobExists

func (this *Tx) JobExists(id string) (bool, error)

JobExists reports whether a job still waits for its result.

func (*Tx) LatestChangeSeq

func (this *Tx) LatestChangeSeq() (result int64, err error)

LatestChangeSeq is the sequence of the newest entry of the change stream, 0 if it is empty.

func (*Tx) ListActivities

func (this *Tx) ListActivities(instanceId string, options model.ActivityListOptions) (result []model.Activity, err error)

func (*Tx) ListApplied

func (this *Tx) ListApplied() (result []Applied, err error)

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

func (this *Tx) ListDesired(networkId string, kind string) (result []Desired, err error)

ListDesired lists the desired state of a network, of one kind if kind is set.

func (*Tx) ListElementStats

func (this *Tx) ListElementStats(instanceId string, run int) (result []model.ElementStats, err error)

func (*Tx) ListEventDescriptions

func (this *Tx) ListEventDescriptions(deploymentId string) (result []model.EventDescription, err error)

func (*Tx) ListIncidents

func (this *Tx) ListIncidents(namespace string, options model.IncidentListOptions, access Access) (result model.Page[model.Incident], err error)

func (*Tx) ListInstances

func (this *Tx) ListInstances(namespace string, options model.InstanceListOptions, access Access) (result model.Page[model.Instance], err error)

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) ListJobs

func (this *Tx) ListJobs(instanceId string) (result []Job, err error)

ListJobs lists the jobs of an instance.

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 (this *Tx) ListModels(namespace string, options model.ModelListOptions, access Access) (result model.Page[model.Model], err error)

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) ListNamespaces

func (this *Tx) ListNamespaces() (result []model.Namespace, err error)

func (*Tx) ListNetworks

func (this *Tx) ListNetworks(ids []string) (result []Network, err error)

ListNetworks reads the given networks, all if ids is nil.

func (*Tx) ListRuns

func (this *Tx) ListRuns(instanceId string) ([]model.Run, error)

func (*Tx) ListSchedules

func (this *Tx) ListSchedules(namespace string, options model.ScheduleListOptions, access Access) (result model.Page[model.Schedule], err error)

func (*Tx) ListSubscriptions

func (this *Tx) ListSubscriptions(instanceId string) ([]Subscription, error)

func (*Tx) ListSubtasks

func (this *Tx) ListSubtasks(jobId string) ([]Subtask, error)

func (*Tx) ListTokens

func (this *Tx) ListTokens(instanceId string) (result []Token, err error)

func (*Tx) LockNetwork

func (this *Tx) LockNetwork(id string, now time.Time) (Network, error)

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

func (this *Tx) MarkNamespaceUnregistered(kind model.Kind, namespace string) error

MarkNamespaceUnregistered schedules all resources of a kind in a namespace for registration, e.g. when a level becomes registered.

func (*Tx) MarkRegistered

func (this *Tx) MarkRegistered(kind model.Kind, id string, owner string) (bool, error)

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

func (this *Tx) MarkUnregistered(kind model.Kind, id string) error

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 (this *Tx) ModelsAfter(afterId string, limit int) (result []string, err error)

func (*Tx) ModuleErrors

func (this *Tx) ModuleErrors(instanceIds []string) (map[string]model.Module, error)

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

func (this *Tx) NamespaceInUse(name string) (bool, error)

NamespaceInUse reports whether models, deployments or instances belong to the namespace.

func (*Tx) NetworkInstanceIds

func (this *Tx) NetworkInstanceIds(networkId string) (result []string, err error)

NetworkInstanceIds lists the instances of a gateway, for its snapshot (LONG-10).

func (*Tx) NextJobDue

func (this *Tx) NextJobDue() (*time.Time, error)

func (*Tx) NextRestartDue

func (this *Tx) NextRestartDue() (*time.Time, error)

func (*Tx) NextStartTimerDue

func (this *Tx) NextStartTimerDue() (*time.Time, error)

func (*Tx) NextTimerDue

func (this *Tx) NextTimerDue() (*time.Time, error)

func (*Tx) OldestChangeSeq

func (this *Tx) OldestChangeSeq() (result int64, err error)

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

func (this *Tx) OldestSnapshotSeq(instanceId string) (seq int64, found bool, err error)

OldestSnapshotSeq is the sequence of the oldest snapshot of an instance; false if there is none.

func (*Tx) OwnedCounts

func (this *Tx) OwnedCounts(userId string) (map[string]int, error)

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

func (this *Tx) PendingRegistrations(kind model.Kind, limit int) (result []Registration, err error)

PendingRegistrations lists resources not yet registered in permissions-v2.

func (*Tx) PruneAppliedInstances

func (this *Tx) PruneAppliedInstances() (int64, error)

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

func (this *Tx) PurgeChanges(before time.Time, limit int) (int64, error)

PurgeChanges removes entries older than before, at most limit at a time (LONG-05).

func (*Tx) PurgeEventTombstones

func (this *Tx) PurgeEventTombstones(before time.Time) error

func (*Tx) PurgeReceipts

func (this *Tx) PurgeReceipts(before time.Time) (int64, error)

func (*Tx) QueueRemoval

func (this *Tx) QueueRemoval(topic string, id string, at time.Time) error

func (*Tx) RecordElementError

func (this *Tx) RecordElementError(instanceId string, run int, elementId string, message string, at time.Time) error

func (*Tx) RemoveEventDescriptions

func (this *Tx) RemoveEventDescriptions(deploymentId string, now time.Time) error

RemoveEventDescriptions runs before a deployment is deleted.

func (*Tx) RemoveModulesOfInstance

func (this *Tx) RemoveModulesOfInstance(instanceId string) (int, error)

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 (this *Tx) RetryModuleRemoval(moduleId string, next time.Time, message string) error

func (*Tx) RetryNotification

func (this *Tx) RetryNotification(id string, due time.Time, message string) error

func (*Tx) RetryRemoval

func (this *Tx) RetryRemoval(topic string, id string, due time.Time, message string) error

func (*Tx) RunningVersions

func (this *Tx) RunningVersions(deploymentId string) (result []int, err error)

RunningVersions returns the deployment versions that still have running instances.

func (*Tx) SaveJob

func (this *Tx) SaveJob(j Job) error

func (*Tx) SaveSchedule

func (this *Tx) SaveSchedule(s model.Schedule) error

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) SaveToken

func (this *Tx) SaveToken(t Token) error

func (*Tx) SaveWatch

func (this *Tx) SaveWatch(w Watch) error

SaveWatch creates or replaces a watch; a replaced one starts over with a new baseline.

func (*Tx) SetApplied

func (this *Tx) SetApplied(a Applied) error

func (*Tx) SetDeploymentDisabled

func (this *Tx) SetDeploymentDisabled(id string, disabled bool) error

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) SetInstanceInfo

func (this *Tx) SetInstanceInfo(id string, namespace string, name string, description string) error

SetInstanceInfo changes name and description of an instance.

func (*Tx) SetIoValue

func (this *Tx) SetIoValue(userId string, v model.IoValue) error

SetIoValue stores a value; deployment and instance ids bind it to their lifetime (IO-03).

func (*Tx) SetModuleCheck

func (this *Tx) SetModuleCheck(id string, message string, at time.Time) error

SetModuleCheck stores the result of a health check; an empty message clears the error.

func (*Tx) SetOwner

func (this *Tx) SetOwner(kind model.Kind, id string, owner string) error

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 (this *Tx) SetStartEventDue(deploymentId string, elementId string, due *time.Time) error

func (*Tx) SetStartVariables

func (this *Tx) SetStartVariables(instanceId string, variables map[string]any) error

SetStartVariables replaces the stored start variables, e.g. after a parameter change (SMS-09).

func (*Tx) SetSubtaskResult

func (this *Tx) SetSubtaskResult(jobId string, subId string, value any) (bool, error)

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) SetSyncPosition

func (this *Tx) SetSyncPosition(name string, position int64) error

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

func (this *Tx) StaleNetworks(before time.Time) (result []string, err error)

StaleNetworks lists networks without contact since before (SYNC-07).

func (*Tx) StalledInstances

func (this *Tx) StalledInstances(before time.Time) (map[string]int, error)

StalledInstances counts running instances per namespace without element change since before (LONG-13).

func (*Tx) StorageRows

func (this *Tx) StorageRows() (map[string]int, error)

StorageRows counts rows per table, for the storage metrics (LONG-14).

func (*Tx) SyncPosition

func (this *Tx) SyncPosition(name string) (result int64, err error)

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

func (this *Tx) TrimActivities(instanceId string, minSeq int64) error

TrimActivities removes entries with a sequence number below minSeq (LONG-03).

func (*Tx) TrimChanges

func (this *Tx) TrimChanges(before time.Time, limit int) (int64, error)

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

func (this *Tx) TrimHistory(column string, value string, before time.Time) error

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

func (this *Tx) TrimModelVersions(modelId string, keep int) error

TrimModelVersions keeps the newest versions of a model and every version a deployment refers to (MOD-07).

func (*Tx) TrimOldestHistory

func (this *Tx) TrimOldestHistory(limit int) (int64, error)

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

func (this *Tx) TrimSnapshots(instanceId string, activityMinSeq int64, keep int) error

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 (this *Tx) UpdateInstance(i Instance) error

func (*Tx) UpdateModel

func (this *Tx) UpdateModel(m model.Model) error

func (*Tx) UpdateNamespace

func (this *Tx) UpdateNamespace(ns model.Namespace, at time.Time) error

func (*Tx) UpdateNetwork

func (this *Tx) UpdateNetwork(n Network) error

func (*Tx) UpdateRun

func (this *Tx) UpdateRun(r model.Run) error

func (*Tx) UpdateWatch

func (this *Tx) UpdateWatch(id string, hash string, message string) error

UpdateWatch stores the result of a check.

func (*Tx) UpsertModule

func (this *Tx) UpsertModule(m model.Module) error

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

func (this *Tx) UpsertReplicatedInstance(networkId string, i model.Instance) error

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).

func (*Tx) UsedBytes

func (this *Tx) UsedBytes() (int64, error)

UsedBytes is the size of the data; free pages of SQLite are reused and not counted (LONG-07).

func (*Tx) UserDependents

func (this *Tx) UserDependents(userId string) (result []model.Dependent, err error)

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.

func (*Tx) VariablesSize

func (this *Tx) VariablesSize(instanceId string) (int, error)

VariablesSize sums the JSON size of all variables of an instance (LONG-08).

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).

Directories

Path Synopsis
Package storetest opens stores for tests: SQLite in memory and Postgres in a container.
Package storetest opens stores for tests: SQLite in memory and Postgres in a container.

Jump to

Keyboard shortcuts

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