db

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnitOfWork

func UnitOfWork(ctx context.Context, db WorkflowDBBackend, f func(tx WorkflowTxBackend) error) (err error)

UnitOfWork runs a function and commit the database at the end or rollback if the function returns an error

Types

type ErrAlreadyExists

type ErrAlreadyExists struct {
	Type, ID string
}

func (ErrAlreadyExists) Error

func (e ErrAlreadyExists) Error() string

type ErrNotFound

type ErrNotFound struct {
	Type, ID string
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type Scene

type Scene struct {
	common.Scene
	Status  common.Status `json:"status"`
	Message string        `json:"message"`
}

type Status

type Status struct {
	New, Pending, Done, Retry, Failed int64
}

func (*Status) Set

func (s *Status) Set(status common.Status, nb int64)

Set the number of occurences for a given status

type Tile

type Tile struct {
	common.Tile
	Status      common.Status `json:"status"`
	Message     string        `json:"message"`
	PreviousID  *int
	ReferenceID *int
}

type WorkflowBackend

type WorkflowBackend interface {
	// Create an AOI in database, may return ErrAlreadyExists
	CreateAOI(ctx context.Context, aoi string) error
	// AOIs returns the list of the aois fitting the pattern
	// pattern [optional=""] aoi_patern
	AOIs(ctx context.Context, pattern string) ([]string, error)
	// Delete an AOI from the database
	DeleteAOI(ctx context.Context, aoi string) error

	// Returns the status of the scenes of the aoi
	ScenesStatus(ctx context.Context, aoi string) (Status, error)
	// Create a new scene, returning its id
	CreateScene(ctx context.Context, sourceID, aoi string, status common.Status, data common.SceneAttrs) (int, error)
	// Get scene with the given id, may return ErrNotFound
	// If a scenesCache is provided, try first to get the scene from the map. Otherwise, the map is updated
	Scene(ctx context.Context, id int, scenesCache *map[int]Scene) (Scene, error)
	// List scenes of the given AOI
	Scenes(ctx context.Context, aoi string) ([]Scene, error)
	// Update scene status & message (if != nil)
	UpdateScene(ctx context.Context, id int, status common.Status, message *string) error
	// Update scene data
	UpdateSceneAttrs(ctx context.Context, id int, data common.SceneAttrs) error
	// Returns the id of a scene. May return ErrNotFound
	SceneId(ctx context.Context, aoi, sourceID string) (int, error)

	// Returns the status of the tiles of the aoi
	TilesStatus(ctx context.Context, aoi string) (Status, error)
	// Create a new tile, returning its id
	// prevTileSource == "" || refTileSource == "" => root tile
	CreateTile(ctx context.Context, sourceID string, sceneID int, data common.TileAttrs, aoi, prevTileSource, prevSceneSource, refTileSource, refSceneSource string) (int, error)
	// Get tile with the given id and status of the scene. May return ErrNotFound
	// If loadScene, the scene is also loaded
	Tile(ctx context.Context, id int, loadScene bool) (Tile, common.Status, error)
	// Tiles returns the list of tiles fitting the given parameters
	// aoi [optional=""] aoi
	// sceneID [optional=0] sceneID
	// status [optional=""] status of the tile
	// loadScene also loads the scenes
	Tiles(ctx context.Context, aoi string, sceneID int, status string, loadScene bool) ([]Tile, error)
	// Get root tiles (no prev and no ref tiles) and their scene.
	RootTiles(ctx context.Context, aoi string) ([]common.Tile, error)
	// Get leaf tiles (no next tiles) and their scene.
	LeafTiles(ctx context.Context, aoi string) ([]common.Tile, error)
	// Update tile status & message (if != nil)
	UpdateTile(ctx context.Context, id int, status common.Status, message *string, resetPrev bool) error
	// Set status of given tiles
	SetTilesStatus(ctx context.Context, ids []int, status common.Status) error
	// Update status of tiles given previous tile ID, current status and scene status
	// Returns updated tiles and their scenesID
	UpdateNextTilesStatus(ctx context.Context, prevID int, status, sceneStatus, newStatus common.Status) ([]Tile, []int, error)
	// Update status of tiles given scene ID, current status and status of previous tile
	// Returns updated tiles, previous tiles and previous scenes ID
	UpdateSceneTilesStatus(ctx context.Context, sceneID int, status, prevStatus, newStatus common.Status) ([]Tile, []Tile, []int, error)
	// Same as UpdateSceneTilesStatus, but only updates root tiles
	UpdateSceneRootTilesStatus(ctx context.Context, sceneID int, status, newStatus common.Status) ([]Tile, error)
	// Update next tile, setting newPrevID
	// Returns list of modified tiles
	UpdateNextTilesPrevId(ctx context.Context, oldPrevID int, newPrevID *int) ([]int, error)
	// Update ref tile, setting newRefID
	// Returns list of modified tiles
	UpdateRefTiles(ctx context.Context, oldRefID int, newRefID int) error
	// Update tile data
	UpdateTileAttrs(ctx context.Context, id int, data common.TileAttrs) error
}

type WorkflowDBBackend

type WorkflowDBBackend interface {
	WorkflowBackend
	StartTransaction(ctx context.Context) (WorkflowTxBackend, error)
}

type WorkflowTxBackend

type WorkflowTxBackend interface {
	WorkflowBackend
	// Must be call to apply transaction
	Commit() error
	// Might be called to cancel the transaction (no effect if commit has already be done)
	Rollback() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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