queue

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const FOO = 100

Variables

This section is empty.

Functions

func ExecuteTask added in v0.2.0

func ExecuteTask(task TaskExecutor, instance TaskInstance, c chan<- ExecuteTaskErr)

func NewTaskId added in v0.2.0

func NewTaskId() string

func ReadTaskData added in v0.2.0

func ReadTaskData[T any](jsonData []byte) (T, error)

func UnwrapChannel added in v0.2.0

func UnwrapChannel(c chan ExecuteTaskErr) []error

Types

type ExecuteTaskErr added in v0.2.0

type ExecuteTaskErr struct {
	Name  string
	Error error
}

func NewExecutTaskErr added in v0.2.0

func NewExecutTaskErr(name string, err error) ExecuteTaskErr

type MasterQ added in v0.2.0

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

MasterQ has two tasks: first, it's a repository of registered task instances; second, it's the primary interface to the file system saving and retrieving of task execution instances.

func New added in v0.2.0

func New(root string, fs afero.Fs, perm os.FileMode) (*MasterQ, error)

New will retrieve the queue if the path already exists, or else create a new queue and register it. **rootDir** must be a valid path.

func (*MasterQ) Enqueue added in v0.2.0

func (q *MasterQ) Enqueue(name string) TaskQueue

func (*MasterQ) Get added in v0.2.0

func (q *MasterQ) Get(name string) (TaskQueue, error)

func (*MasterQ) Has added in v0.2.0

func (q *MasterQ) Has(name string) bool

func (*MasterQ) Register added in v0.2.0

func (q *MasterQ) Register(task TaskExecutor, name string) error

Register the given instance of the task interface. The task is registered by the derrived name.

func (*MasterQ) RunAllTasks added in v0.2.0

func (q *MasterQ) RunAllTasks() []error

type Path added in v0.2.0

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

func NewPath added in v0.2.0

func NewPath(path string, fs afero.Fs, fileMode os.FileMode) Path

func (Path) Copy added in v0.2.0

func (pth Path) Copy() Path

func (Path) Exists added in v0.2.0

func (pth Path) Exists() bool

func (Path) HasError added in v0.2.0

func (pth Path) HasError() bool

func (Path) IsDir added in v0.2.0

func (pth Path) IsDir() bool

func (Path) IsFile added in v0.2.0

func (pth Path) IsFile() bool

func (Path) Join added in v0.2.0

func (pth Path) Join(paths ...string) Path

func (Path) MkDir added in v0.2.0

func (pth Path) MkDir() error

func (Path) MkDirs added in v0.2.0

func (pth Path) MkDirs() error

func (Path) ModTime added in v0.2.0

func (pth Path) ModTime() (time.Time, error)

func (Path) Name added in v0.2.0

func (pth Path) Name() string

func (Path) Parent added in v0.2.0

func (pth Path) Parent() Path

func (Path) Read added in v0.2.0

func (pth Path) Read() ([]byte, error)

func (Path) ReadDir added in v0.2.0

func (pth Path) ReadDir() ([]Path, error)

func (Path) Remove added in v0.2.0

func (pth Path) Remove() error

func (Path) Resolve added in v0.2.0

func (pth Path) Resolve() Path

func (Path) SetErr added in v0.2.0

func (pth Path) SetErr(err error) Path

func (Path) SetPath added in v0.2.0

func (pth Path) SetPath(path string) Path

func (Path) Stat added in v0.2.0

func (pth Path) Stat() (os.FileInfo, error)

func (Path) Stem added in v0.2.0

func (pth Path) Stem() string

func (Path) String added in v0.2.0

func (pth Path) String() string

func (Path) Suffix added in v0.2.0

func (pth Path) Suffix() string

func (Path) Write added in v0.2.0

func (pth Path) Write(data []byte) error

type TaskErrors added in v0.2.0

type TaskErrors struct {
	Errors []TaskExecutionError `json:"errors"`
}

func (*TaskErrors) Add added in v0.2.0

func (te *TaskErrors) Add(err TaskExecutionError)

func (*TaskErrors) Count added in v0.2.0

func (te *TaskErrors) Count() int

func (*TaskErrors) ReadFrom added in v0.2.0

func (te *TaskErrors) ReadFrom(errFile Path) error

func (*TaskErrors) WriteTo added in v0.2.0

func (te *TaskErrors) WriteTo(errFile Path) error

type TaskExecutionError added in v0.2.0

type TaskExecutionError struct {
	Timestamp time.Time `json:"timestamp"`
	Error     string    `json:"error"`
	Traceback string    `json:"traceback"`
}

type TaskExecutor added in v0.2.0

type TaskExecutor interface {
	Assert(any) error
	Execute([]byte) error
}

TaskExecutor interface is what must be implemented for loq to register and execute a defined task.

type TaskHandler added in v0.2.0

type TaskHandler func(instance TaskInstance)

type TaskInstance added in v0.2.0

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

TaskInstance represents a unique task and is represented on a file system as a directory that contains at least a single json file with that task's execution arguments. The task directory can also contain a lock file and/or an error file.

func (TaskInstance) ApplyLock added in v0.2.0

func (tq TaskInstance) ApplyLock() error

ApplyLock create a .lock file in the task folder.

func (TaskInstance) ErrorFile added in v0.2.0

func (tq TaskInstance) ErrorFile() Path

ErrorFile returns the Path object of the task error file.

func (TaskInstance) Exists added in v0.2.0

func (tq TaskInstance) Exists() bool

Exists is true if the task folder exists.

func (TaskInstance) GetErrors added in v0.2.0

func (tq TaskInstance) GetErrors() (TaskErrors, error)

func (TaskInstance) HasError added in v0.2.0

func (tq TaskInstance) HasError() bool

HasError is true if the task folder contains a .error ffile.

func (TaskInstance) Initialize added in v0.2.0

func (ti TaskInstance) Initialize() error

Initialize creates the task directory and applies a lock.

func (TaskInstance) IsLocked added in v0.2.0

func (tq TaskInstance) IsLocked() bool

IsLocked is true if the task folder contains a .lock file.

func (TaskInstance) IsReady added in v0.2.0

func (tq TaskInstance) IsReady() bool

IsReady is true if the task folder has a task file and is not locked and has no errors.

func (TaskInstance) LockFile added in v0.2.0

func (tq TaskInstance) LockFile() Path

LockFile returns the Path object of the task lock file.

func (TaskInstance) ReleaseLock added in v0.2.0

func (ti TaskInstance) ReleaseLock() error

ReleaseLock deletes the .lock file in the task folder.

func (TaskInstance) Remove added in v0.2.0

func (tq TaskInstance) Remove() error

Remove deletes the task folder and all it's files.

func (TaskInstance) String added in v0.2.0

func (tq TaskInstance) String() string

func (TaskInstance) TaskDir added in v0.2.0

func (tq TaskInstance) TaskDir() Path

TaskDir returns the Path object for the task dir.

func (TaskInstance) TaskFile added in v0.2.0

func (tq TaskInstance) TaskFile() Path

TaskFile returns the Path object fof the task file.

func (TaskInstance) WriteError added in v0.2.0

func (tq TaskInstance) WriteError(msg string, traceback string) error

WriteError writes an error message to the tasks error file.

type TaskQueue

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

func NewTaskQueue

func NewTaskQueue(master Path, name string, task TaskExecutor) (TaskQueue, error)

func (TaskQueue) CreateTaskInstance added in v0.2.0

func (tq TaskQueue) CreateTaskInstance() TaskInstance

func (TaskQueue) GetTaskInstances added in v0.2.0

func (tq TaskQueue) GetTaskInstances() ([]TaskInstance, error)

func (TaskQueue) Initialize added in v0.2.0

func (tq TaskQueue) Initialize() error

func (TaskQueue) IterTaskInstances added in v0.2.0

func (tq TaskQueue) IterTaskInstances(handler TaskHandler) error

func (TaskQueue) LoadTaskInstance added in v0.2.0

func (tq TaskQueue) LoadTaskInstance(taskDir Path) TaskInstance

func (TaskQueue) Run added in v0.2.0

func (tq TaskQueue) Run(opt any) (TaskInstance, error)

Run creates a new TaskInstance on disk with the given task arguments, and then immediately executes.

func (TaskQueue) Send

func (tq TaskQueue) Send(opt any) (TaskInstance, error)

Send creates a new TaskInstance on disk with the given task arguments.

func (TaskQueue) Task added in v0.2.0

func (tq TaskQueue) Task() TaskExecutor

Jump to

Keyboard shortcuts

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