storage

package
v0.0.0-...-0202b1c Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMStoreError    = errors.New("mstore gave error response")
	ErrInvalidTask    = errors.New("invalid task")
	ErrInvalidMessage = errors.New("task contains invalid message")
)
View Source
var (
	ErrInvalidConfiguration     = errors.New("invalid configuration")
	ErrIncompatibleSQLMigration = errors.New("incompatible migration")
	ErrNotEnoughSQLMigrations   = errors.New("already more migrations than wanted")
	ErrSqliteFailure            = errors.New("sqlite returned an error")
)
View Source
var (
	ErrTaskNotFound = errors.New("task was not found")
)

Functions

func MergeNewTaskSet

func MergeNewTaskSet(oldTasks []*task.LocalTask, newTasks []*task.Task) []*task.LocalTask

MergeNewTaskSet updates a local set of tasks with a remote one

The new set is leading and tasks that are not in there get dismissed. Tasks that were created locally and got dispatched might temporarily dissappear if the remote inbox has a delay in processing.

func NextLocalId

func NextLocalId(used []int) int

NextLocalId finds a new local id by incrememting to a variable limit.

When tasks are edited, some get removed because they are done or deleted. It is very confusing if existing tasks get renumbered, or if a new one immediatly gets the id of an removed one. So it is better to just increment. However, local id's also benefit from being short, so we don't want to keep incrementing forever.

This function takes a list if id's that are in use and sets the limit to the nearest power of ten depening on the current highest id used. The new id is an incremented one from that max. However, if the limit is reached, it first tries to find "holes" in the current sequence, starting from the bottom. If there are no holes, the limit is increased.

Types

type Dispatcher

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

func NewDispatcher

func NewDispatcher(msender msend.MSender) *Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(t *task.Task) error

type LocalRepository

type LocalRepository interface {
	LatestSyncs() (time.Time, time.Time, error) // last fetch, last dispatch, err
	SetTasks(tasks []*task.Task) error
	FindAll() ([]*task.LocalTask, error)
	FindById(id string) (*task.LocalTask, error)
	FindByLocalId(id int) (*task.LocalTask, error)
	SetLocalUpdate(id string, update *task.LocalUpdate) error
	MarkDispatched(id int) error
	Add(update *task.LocalUpdate) (*task.LocalTask, error)
}

type Memory

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

Memory is an in memory implementation of LocalRepository

func NewMemory

func NewMemory(initTasks ...*task.Task) *Memory

func (*Memory) Add

func (m *Memory) Add(update *task.LocalUpdate) (*task.LocalTask, error)

func (*Memory) FindAll

func (m *Memory) FindAll() ([]*task.LocalTask, error)

func (*Memory) FindById

func (m *Memory) FindById(id string) (*task.LocalTask, error)

func (*Memory) FindByLocalId

func (m *Memory) FindByLocalId(localId int) (*task.LocalTask, error)

func (*Memory) LatestSyncs

func (m *Memory) LatestSyncs() (time.Time, time.Time, error)

func (*Memory) MarkDispatched

func (m *Memory) MarkDispatched(localId int) error

func (*Memory) SetLocalUpdate

func (m *Memory) SetLocalUpdate(id string, update *task.LocalUpdate) error

func (*Memory) SetTasks

func (m *Memory) SetTasks(tasks []*task.Task) error

type RemoteRepository

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

func NewRemoteRepository

func NewRemoteRepository(ms mstore.MStorer) *RemoteRepository

func (*RemoteRepository) Add

func (rr *RemoteRepository) Add(t *task.Task) error

func (*RemoteRepository) CleanUp

func (rr *RemoteRepository) CleanUp() error

Cleanup removes older versions of tasks

func (*RemoteRepository) FindAll

func (rr *RemoteRepository) FindAll(folder string) ([]*task.Task, error)

func (*RemoteRepository) Remove

func (rr *RemoteRepository) Remove(tasks []*task.Task) error

func (*RemoteRepository) Update

func (rr *RemoteRepository) Update(t *task.Task) error

type Sqlite

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

Sqlite is an sqlite implementation of LocalRepository

func NewSqlite

func NewSqlite(conf *SqliteConfig) (*Sqlite, error)

func (*Sqlite) Add

func (s *Sqlite) Add(update *task.LocalUpdate) (*task.LocalTask, error)

func (*Sqlite) FindAll

func (s *Sqlite) FindAll() ([]*task.LocalTask, error)

func (*Sqlite) FindById

func (s *Sqlite) FindById(id string) (*task.LocalTask, error)

func (*Sqlite) FindByLocalId

func (s *Sqlite) FindByLocalId(localId int) (*task.LocalTask, error)

func (*Sqlite) LatestSyncs

func (s *Sqlite) LatestSyncs() (time.Time, time.Time, error)

func (*Sqlite) MarkDispatched

func (s *Sqlite) MarkDispatched(localId int) error

func (*Sqlite) SetLocalUpdate

func (s *Sqlite) SetLocalUpdate(id string, update *task.LocalUpdate) error

func (*Sqlite) SetTasks

func (s *Sqlite) SetTasks(tasks []*task.Task) error

type SqliteConfig

type SqliteConfig struct {
	DBPath string
}

Jump to

Keyboard shortcuts

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