datastore

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DATASTORE_INMEMORY = "inmemory"
	DATASTORE_POSTGRES = "postgres"
)

Variables

View Source
var ErrContextNotFound = errors.New("context not found")
View Source
var ErrJobNotFound = errors.New("job not found")
View Source
var ErrNodeNotFound = errors.New("node not found")
View Source
var (
	ErrProviderNotFound = errors.Errorf("datastore provider not found")
)
View Source
var ErrTaskNotFound = errors.New("task not found")

Functions

func RegisterProvider added in v0.1.2

func RegisterProvider(name string, provider Provider)

Types

type Datastore

type Datastore interface {
	CreateTask(ctx context.Context, t *tork.Task) error
	UpdateTask(ctx context.Context, id string, modify func(u *tork.Task) error) error
	GetTaskByID(ctx context.Context, id string) (*tork.Task, error)
	GetActiveTasks(ctx context.Context, jobID string) ([]*tork.Task, error)

	CreateNode(ctx context.Context, n tork.Node) error
	UpdateNode(ctx context.Context, id string, modify func(u *tork.Node) error) error
	GetNodeByID(ctx context.Context, id string) (tork.Node, error)
	GetActiveNodes(ctx context.Context) ([]tork.Node, error)

	CreateJob(ctx context.Context, j *tork.Job) error
	UpdateJob(ctx context.Context, id string, modify func(u *tork.Job) error) error
	GetJobByID(ctx context.Context, id string) (*tork.Job, error)
	GetJobs(ctx context.Context, q string, page, size int) (*Page[*tork.Job], error)

	GetStats(ctx context.Context) (*tork.Stats, error)

	WithTx(ctx context.Context, f func(tx Datastore) error) error
}

func NewFromProvider added in v0.1.2

func NewFromProvider(name string) (Datastore, error)

type InMemoryDatastore

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

func NewInMemoryDatastore

func NewInMemoryDatastore() *InMemoryDatastore

func (*InMemoryDatastore) CreateJob

func (ds *InMemoryDatastore) CreateJob(ctx context.Context, j *tork.Job) error

func (*InMemoryDatastore) CreateNode

func (ds *InMemoryDatastore) CreateNode(ctx context.Context, n tork.Node) error

func (*InMemoryDatastore) CreateTask

func (ds *InMemoryDatastore) CreateTask(ctx context.Context, t *tork.Task) error

func (*InMemoryDatastore) GetActiveNodes

func (ds *InMemoryDatastore) GetActiveNodes(ctx context.Context) ([]tork.Node, error)

func (*InMemoryDatastore) GetActiveTasks

func (ds *InMemoryDatastore) GetActiveTasks(ctx context.Context, jobID string) ([]*tork.Task, error)

func (*InMemoryDatastore) GetJobByID

func (ds *InMemoryDatastore) GetJobByID(ctx context.Context, id string) (*tork.Job, error)

func (*InMemoryDatastore) GetJobs

func (ds *InMemoryDatastore) GetJobs(ctx context.Context, q string, page, size int) (*Page[*tork.Job], error)

func (*InMemoryDatastore) GetNodeByID

func (ds *InMemoryDatastore) GetNodeByID(ctx context.Context, id string) (tork.Node, error)

func (*InMemoryDatastore) GetStats

func (ds *InMemoryDatastore) GetStats(ctx context.Context) (*tork.Stats, error)

func (*InMemoryDatastore) GetTaskByID

func (ds *InMemoryDatastore) GetTaskByID(ctx context.Context, id string) (*tork.Task, error)

func (*InMemoryDatastore) UpdateJob

func (ds *InMemoryDatastore) UpdateJob(ctx context.Context, id string, modify func(u *tork.Job) error) error

func (*InMemoryDatastore) UpdateNode

func (ds *InMemoryDatastore) UpdateNode(ctx context.Context, id string, modify func(u *tork.Node) error) error

func (*InMemoryDatastore) UpdateTask

func (ds *InMemoryDatastore) UpdateTask(ctx context.Context, id string, modify func(u *tork.Task) error) error

func (*InMemoryDatastore) WithTx

func (ds *InMemoryDatastore) WithTx(ctx context.Context, f func(tx Datastore) error) error

type Page

type Page[T any] struct {
	Items      []T `json:"items"`
	Number     int `json:"number"`
	Size       int `json:"size"`
	TotalPages int `json:"totalPages"`
	TotalItems int `json:"totalItems"`
}

type PostgresDatastore

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

func NewPostgresDataStore

func NewPostgresDataStore(dsn string) (*PostgresDatastore, error)

func (*PostgresDatastore) CreateJob

func (ds *PostgresDatastore) CreateJob(ctx context.Context, j *tork.Job) error

func (*PostgresDatastore) CreateNode

func (ds *PostgresDatastore) CreateNode(ctx context.Context, n tork.Node) error

func (*PostgresDatastore) CreateTask

func (ds *PostgresDatastore) CreateTask(ctx context.Context, t *tork.Task) error

func (*PostgresDatastore) ExecScript

func (ds *PostgresDatastore) ExecScript(script string) error

func (*PostgresDatastore) GetActiveNodes

func (ds *PostgresDatastore) GetActiveNodes(ctx context.Context) ([]tork.Node, error)

func (*PostgresDatastore) GetActiveTasks

func (ds *PostgresDatastore) GetActiveTasks(ctx context.Context, jobID string) ([]*tork.Task, error)

func (*PostgresDatastore) GetJobByID

func (ds *PostgresDatastore) GetJobByID(ctx context.Context, id string) (*tork.Job, error)

func (*PostgresDatastore) GetJobs

func (ds *PostgresDatastore) GetJobs(ctx context.Context, q string, page, size int) (*Page[*tork.Job], error)

func (*PostgresDatastore) GetNodeByID

func (ds *PostgresDatastore) GetNodeByID(ctx context.Context, id string) (tork.Node, error)

func (*PostgresDatastore) GetStats

func (ds *PostgresDatastore) GetStats(ctx context.Context) (*tork.Stats, error)

func (*PostgresDatastore) GetTaskByID

func (ds *PostgresDatastore) GetTaskByID(ctx context.Context, id string) (*tork.Task, error)

func (*PostgresDatastore) UpdateJob

func (ds *PostgresDatastore) UpdateJob(ctx context.Context, id string, modify func(u *tork.Job) error) error

func (*PostgresDatastore) UpdateNode

func (ds *PostgresDatastore) UpdateNode(ctx context.Context, id string, modify func(u *tork.Node) error) error

func (*PostgresDatastore) UpdateTask

func (ds *PostgresDatastore) UpdateTask(ctx context.Context, id string, modify func(t *tork.Task) error) error

func (*PostgresDatastore) WithTx

func (ds *PostgresDatastore) WithTx(ctx context.Context, f func(tx Datastore) error) error

type Provider added in v0.1.1

type Provider func() (Datastore, error)

Jump to

Keyboard shortcuts

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