storage

package
v0.0.0-...-a20aad9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TableMigrations = []any{
	&Instance{},
	&Process{},
	&AuditLog{},
	&Incident{},
	&Job{},
	&Variable{},
	&BpmnResource{},
}

List of migrations to be run on database during initialization.

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

Migrate all tables in database automatically.

func ConnectDb

func ConnectDb(dsnConfig DsnConfig, maxRetries int, retryDelay time.Duration) (*gorm.DB, error)

Connect to database by DsnConfig.

Types

type AuditLog

type AuditLog struct {
	Position           int64     `gorm:"primarykey"`
	ProcessInstanceKey int64     `gorm:"not null"`
	ElementID          string    `gorm:"not null"`
	ElementType        string    `gorm:"not null"`
	Intent             string    `gorm:"not null"`
	Time               time.Time `gorm:"not null"`
}

func (AuditLog) TableName

func (AuditLog) TableName() string

type BpmnResource

type BpmnResource struct {
	ProcessDefinitionKey int64 `gorm:"primarykey;autoIncrement:false"`
	// A base64 encoded string of the BPMN XML file.
	BpmnFile string `gorm:"not null"`
}

BpmnResource model struct for the 'bpmn_resources' database table.

This table is used to store the BPMN XML files which are relatively large in size. The XML files are stored in the database as a base64 encoded string.

func (BpmnResource) TableName

func (BpmnResource) TableName() string

type DsnConfig

type DsnConfig struct {
	// Username used to log in to the database.
	User string
	// Password of the logging in user.
	Password string
	// Database name to be accessed.
	DatabaseName string
	// The host used to host the database.
	Host string
	// The port used to connect to the database.
	Port uint16
}

Configuration to connect to database.

func (*DsnConfig) String

func (config *DsnConfig) String() string

Create a valid DSN string to connect database from DsnConfig.

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher is used by the API to fetch data from the database.

func NewFetcher

func NewFetcher(db *gorm.DB) *Fetcher

Creates new fetcher.

Database object is assumed to be already initialized.

func (*Fetcher) GetAuditLogsForInstance

func (f *Fetcher) GetAuditLogsForInstance(ctx context.Context, pagination *Pagination, instanceKey int64) (Paginated[AuditLog], error)

Gets all audit logs for an instance.

func (*Fetcher) GetBpmnResource

func (f *Fetcher) GetBpmnResource(ctx context.Context, processDefKey int64) (BpmnResource, error)

Gets a BPMN resource by its process ID.

func (*Fetcher) GetIncidents

func (f *Fetcher) GetIncidents(ctx context.Context, pagination *Pagination) (Paginated[Incident], error)

Gets all incidents.

func (*Fetcher) GetIncidentsForInstance

func (f *Fetcher) GetIncidentsForInstance(ctx context.Context, pagination *Pagination, instanceKey int64) (Paginated[Incident], error)

Gets all incidents for an instance.

func (*Fetcher) GetInstance

func (f *Fetcher) GetInstance(ctx context.Context, instanceKey int64) (Instance, error)

Gets an instance by its key.

func (*Fetcher) GetInstances

func (f *Fetcher) GetInstances(ctx context.Context, pagination *Pagination) (Paginated[Instance], error)

Gets all instances for all processes.

func (*Fetcher) GetInstancesForProcess

func (f *Fetcher) GetInstancesForProcess(ctx context.Context, pagination *Pagination, processDefKey int64) (Paginated[Instance], error)

Gets all instances for a process based on its definition key.

func (*Fetcher) GetJobs

func (f *Fetcher) GetJobs(ctx context.Context, pagination *Pagination) (Paginated[Job], error)

Gets all jobs.

func (*Fetcher) GetJobsForInstance

func (f *Fetcher) GetJobsForInstance(ctx context.Context, pagination *Pagination, instanceKey int64) (Paginated[Job], error)

Gets all jobs for an instance.

func (*Fetcher) GetProcess

func (f *Fetcher) GetProcess(ctx context.Context, processDefKey int64) (Process, error)

Gets a process by its key.

func (*Fetcher) GetProcesses

func (f *Fetcher) GetProcesses(ctx context.Context, pagination *Pagination) (Paginated[Process], error)

Gets all processes.

func (*Fetcher) GetVariablesForInstance

func (f *Fetcher) GetVariablesForInstance(ctx context.Context, pagination *Pagination, filter *Filter, instanceKey int64) (Paginated[Variable], error)

Gets all variables for an instance.

type Filter

type Filter struct {
	Input string
	Type  FilterType
}

Filter is used to filter results with given input on a given field.

func (*Filter) FilterFunctor

func (f *Filter) FilterFunctor(field string) func(*gorm.DB) *gorm.DB

FilterFunctor returns a function that can be used to filter a query. This can be called even if the filter is nil.

NOTE: It is unsafe to use user provided input directly as the field name.

type FilterType

type FilterType string
const (
	FilterTypeIs       FilterType = "IS"
	FilterTypeIsNot    FilterType = "IS_NOT"
	FilterTypeContains FilterType = "CONTAINS"
)

type Incident

type Incident struct {
	Key                int64     `gorm:"primarykey"`
	ProcessInstanceKey int64     `gorm:"not null"`
	ElementID          string    `gorm:"not null"`
	ErrorType          string    `gorm:"not null"`
	ErrorMessage       string    `gorm:"not null"`
	State              string    `gorm:"not null"`
	Time               time.Time `gorm:"not null"`
}

func (Incident) TableName

func (Incident) TableName() string

type Instance

type Instance struct {
	ProcessInstanceKey   int64     `gorm:"primarykey"`
	ProcessDefinitionKey int64     `gorm:"not null"`
	Version              int64     `gorm:"not null"`
	Status               string    `gorm:"not null"`
	StartTime            time.Time `gorm:"not null"`
	EndTime              sql.NullTime
	AuditLogs            []AuditLog `gorm:"foreignKey:ProcessInstanceKey;references:ProcessInstanceKey"`
	Incidents            []Incident `gorm:"foreignKey:ProcessInstanceKey;references:ProcessInstanceKey"`
	Jobs                 []Job      `gorm:"foreignKey:ProcessInstanceKey;references:ProcessInstanceKey"`
	Variables            []Variable `gorm:"foreignKey:ProcessInstanceKey;references:ProcessInstanceKey"`
}

Instance model struct for the 'instances' database table.

func (Instance) TableName

func (Instance) TableName() string

type Job

type Job struct {
	Key                int64     `gorm:"primarykey"`
	ElementID          string    `gorm:"not null"`
	ProcessInstanceKey int64     `gorm:"not null"`
	Type               string    `gorm:"not null"`
	Retries            int64     `gorm:"not null"`
	Worker             string    `gorm:"not null"`
	State              string    `gorm:"not null"`
	Time               time.Time `gorm:"not null"`
}

Job model struct for the 'jobs' database table.

func (Job) TableName

func (Job) TableName() string

type Paginated

type Paginated[T any] struct {
	TotalCount int64
	Items      []T
}

Paginated is a generic type for paginated results.

type Pagination

type Pagination struct {
	Offset int
	Limit  int
}

Pagination is used to limit the number of results returned by a query for performance reasons in tabular views.

type Process

type Process struct {
	ProcessDefinitionKey int64        `gorm:"primarykey"`
	BpmnProcessID        string       `gorm:"not null"`
	Version              int64        `gorm:"not null"`
	DeploymentTime       time.Time    `gorm:"not null"`
	BpmnResource         BpmnResource `gorm:"foreignKey:ProcessDefinitionKey;references:ProcessDefinitionKey"`
	Instances            []Instance   `gorm:"foreignKey:ProcessDefinitionKey;references:ProcessDefinitionKey"`
}

Process model struct for the 'processes' database table.

func (Process) TableName

func (Process) TableName() string

type Storer

type Storer interface {
	ProcessDeployed(
		processDefinitionKey int64,
		bpmnProcessID string,
		version int64,
		deploymentTime time.Time,
		bpmnResourceRaw []byte,
	) error

	ProcessInstanceActivated(
		processInstanceKey int64,
		processDefinitionKey int64,
		version int64,
		startTime time.Time,
	) error

	ProcessInstanceCompleted(
		processInstanceKey int64,
		endTime time.Time,
	) error

	ProcessInstanceTerminated(
		processInstanceKey int64,
		endTime time.Time,
	) error

	VariableCreated(
		processInstanceKey int64,
		name string,
		value string,
		time time.Time,
	) error

	VariableUpdated(
		processInstanceKey int64,
		name string,
		value string,
		time time.Time,
	) error

	IncidentCreated(
		key int64,
		processInstanceKey int64,
		elementID string,
		errorType string,
		errorMessage string,
		time time.Time,
	) error

	IncidentResolved(
		key int64,
		time time.Time,
	) error

	AuditLogEventOccurred(
		position int64,
		processInstanceKey int64,
		elementID string,
		elementType string,
		intent string,
		time time.Time,
	) error

	JobCreated(
		key int64,
		elementID string,
		processInstanceKey int64,
		jobType string,
		retries int64,
		worker string,
		time time.Time,
	) error

	JobUpdated(
		key int64,
		retries int64,
		worker string,
		state string,
		time time.Time,
	) error
}

func NewStorer

func NewStorer(db *gorm.DB) Storer

type Tabler

type Tabler interface {
	TableName() string
}

Interface for models that have a table name. Implementing this interface changes the table's name in GORM and allows it to be queried by generic functions.

type Variable

type Variable struct {
	ProcessInstanceKey int64     `gorm:"primarykey;autoIncrement:false"`
	Name               string    `gorm:"primarykey"`
	Value              string    `gorm:"not null"`
	Time               time.Time `gorm:"not null"`
}

Variable model struct for the 'variables' database table.

func (Variable) TableName

func (Variable) TableName() string

Jump to

Keyboard shortcuts

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