storage

package
v0.0.0-...-5a11e00 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(config config.MongodbConfig) (*connection, error)

Types

type CheckinObj

type CheckinObj struct {
	Step      string    `bson:"step" json:"step"`
	Timestamp time.Time `bson:"timestamp" json:"timestamp"`
}

type KV

type KV map[string]interface{}

type MongoStorage

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

func (*MongoStorage) Create

func (ms *MongoStorage) Create(obj ObjectDTO) (*Object, error)

func (*MongoStorage) FindById

func (ms *MongoStorage) FindById(id string) (*Object, error)

func (*MongoStorage) UpdateById

func (ms *MongoStorage) UpdateById(id string, update KV, operation OperationMap) error

type Object

type Object struct {
	ID           interface{}            `bson:"_id" json:"id"`
	CreatedAt    time.Time              `bson:"createdAt" json:"createdAt"`
	UpdatedAt    time.Time              `bson:"updatedAt" json:"updatedAt"`
	CompletedAt  time.Time              `bson:"completedAt" json:"completedAt"`
	Error        string                 `bson:"error" json:"error"`
	CurrentStep  string                 `bson:"currentStep" json:"currentStep"`
	CommandGraph string                 `bson:"commandGraph" json:"commandGraph"`
	Status       Status                 `bson:"status" json:"status"`
	Params       map[string]interface{} `bson:"params" json:"params"`
}

Update operations must reference this fields by their json tag

type ObjectDTO

type ObjectDTO struct {
	CommandGraph string                 `bson:"commandGraph" json:"commandGraph"`
	Status       Status                 `bson:"status" json:"status"`
	Params       map[string]interface{} `bson:"params" json:"params"`
}

type OperationKey

type OperationKey string
const (
	AddOperation OperationKey = "add"
)

type OperationMap

type OperationMap map[OperationKey]OperationValue

type OperationValue

type OperationValue map[string]interface{}

type Repository

type Repository struct {
	Storage
}

Repository provides utilitarian wrappings around Storage for internal usage

func NewMongoStorage

func NewMongoStorage(config config.MongodbConfig) (*Repository, error)

func NewRepository

func NewRepository(storage Storage) *Repository

func (*Repository) CheckinJob

func (r *Repository) CheckinJob(id string, step string) error

func (*Repository) CompleteJob

func (r *Repository) CompleteJob(id string) error

func (*Repository) CreateJob

func (r *Repository) CreateJob(obj ObjectDTO) (*Object, error)

func (*Repository) FailJob

func (r *Repository) FailJob(id string, err error) error

func (*Repository) StartJob

func (r *Repository) StartJob(id string, step string) error

type Status

type Status string
var (
	Initial    Status = "initial"
	Processing Status = "processing"
	Completed  Status = "completed"
	Failed     Status = "failed"
)

type Storage

type Storage interface {
	Create(obj ObjectDTO) (*Object, error)
	FindById(id string) (*Object, error)
	UpdateById(id string, update KV, operation OperationMap) error
}

Storage provides easy to provide minimalistic approach to abstract persistent storage. Update operation receives map of fields which corresponds to object's json field tags by name.

Jump to

Keyboard shortcuts

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