datastore

package
v0.1.47 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

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

Variables

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

Functions

This section is empty.

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.JobSummary], error)

	GetMetrics(ctx context.Context) (*tork.Metrics, error)

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

	HealthCheck(ctx context.Context) error
}

type InMemoryDatastore

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

func NewInMemoryDatastore

func NewInMemoryDatastore(opts ...Option) *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.JobSummary], error)

func (*InMemoryDatastore) GetMetrics added in v0.1.5

func (ds *InMemoryDatastore) GetMetrics(ctx context.Context) (*tork.Metrics, error)

func (*InMemoryDatastore) GetNodeByID

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

func (*InMemoryDatastore) GetTaskByID

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

func (*InMemoryDatastore) HealthCheck added in v0.1.13

func (ds *InMemoryDatastore) HealthCheck(ctx context.Context) 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 Option added in v0.1.4

type Option = func(ds *InMemoryDatastore)

func WithCleanupInterval added in v0.1.4

func WithCleanupInterval(ci time.Duration) Option

func WithJobExpiration added in v0.1.4

func WithJobExpiration(exp time.Duration) Option

func WithNodeExpiration added in v0.1.4

func WithNodeExpiration(exp time.Duration) Option

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.JobSummary], error)

func (*PostgresDatastore) GetMetrics added in v0.1.5

func (ds *PostgresDatastore) GetMetrics(ctx context.Context) (*tork.Metrics, error)

func (*PostgresDatastore) GetNodeByID

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

func (*PostgresDatastore) GetTaskByID

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

func (*PostgresDatastore) HealthCheck added in v0.1.13

func (ds *PostgresDatastore) HealthCheck(ctx context.Context) 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