database

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequestIdNotFound = fmt.Errorf("request id not found")
	ErrNoStatusDataToday = fmt.Errorf("no status data today")
	ErrNoStatusData      = fmt.Errorf("no status data")
)

Functions

func ParseFile

func ParseFile(file string) (*models.Status, error)

ParseFile parses a status file.

Types

type Config

type Config struct {
	Dir string
}

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is the default configuration for Database.

type Database

type Database struct {
	*Config
}

Database is the interfact to store workflow status in local. It stores status in JSON format in a directory as per each configPath. Multiple JSON data can be stored in a single file and each data is separated by newline. When a data is updated, it appends a new line to the file. Only the latest data in a single file can be read. When Compact is called, it removes old data. Compact must be called only once per file.

func New

func New() *Database

New creates a new Database with default configuration.

func (*Database) Compact

func (db *Database) Compact(configPath, original string) error

Compact creates a new file with only the latest data and removes old data.

func (*Database) FindByRequestId

func (db *Database) FindByRequestId(configPath string, requestId string) (*models.StatusFile, error)

FindByRequestId finds a status file by requestId.

func (*Database) MoveData added in v1.2.4

func (db *Database) MoveData(oldPath, newPath string) error

MoveData moves data from one directory to another.

func (*Database) NewWriter

func (db *Database) NewWriter(configPath string, t time.Time, requestId string) (*Writer, string, error)

NewWriter creates a new writer for a status.

func (*Database) ReadStatusHist

func (db *Database) ReadStatusHist(configPath string, n int) []*models.StatusFile

ReadStatusHist returns a list of status files.

func (*Database) ReadStatusToday

func (db *Database) ReadStatusToday(configPath string) (*models.Status, error)

ReadStatusToday returns a list of status files.

func (*Database) RemoveAll

func (db *Database) RemoveAll(configPath string) error

RemoveAll removes all files in a directory.

func (*Database) RemoveOld

func (db *Database) RemoveOld(configPath string, retentionDays int) error

RemoveOld removes old files.

type Writer

type Writer struct {
	Target string
	// contains filtered or unexported fields
}

Writer is the interface to write status to local file.

func (*Writer) Close

func (w *Writer) Close() (err error)

Close closes the writer.

func (*Writer) Open

func (w *Writer) Open() (err error)

Open opens the writer.

func (*Writer) Write

func (w *Writer) Write(st *models.Status) error

Writer appends the status to the local file.

Jump to

Keyboard shortcuts

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