Documentation
¶
Index ¶
- type Middleware
- type Service
- type Task
- type TaskManager
- func (tm *TaskManager) CancelAll()
- func (tm *TaskManager) CancelTask(id uuid.UUID)
- func (tm *TaskManager) GetResults() <-chan interface{}
- func (tm *TaskManager) GetTask(id uuid.UUID) (task Task, ok bool)
- func (tm *TaskManager) GetTasks() []Task
- func (tm *TaskManager) RegisterTask(tasks ...Task)
- func (tm *TaskManager) Start(numWorkers int)
- func (tm *TaskManager) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
Middleware describes a `Service` middleware.
type Service ¶
type Service interface {
// RegisterTask registers a new task to the worker
RegisterTask(tasks ...Task)
// Start the task manager
Start(numWorkers int)
// Stop the task manage
Stop()
// GetResults gets the results channel
GetResults() <-chan interface{}
// GetTask gets a task by its ID
GetTask(id uuid.UUID) (task Task, ok bool)
// GetTasks gets all tasks
GetTasks() []Task
// CancelAll cancels all tasks
CancelAll()
// CancelTask cancels a task by its ID
CancelTask(id uuid.UUID)
}
Service is an interface for a task manager
func NewTaskManager ¶
NewTaskManager creates a new task manager
func RegisterMiddleware ¶
func RegisterMiddleware(svc Service, mw ...Middleware) Service
RegisterMiddleware registers middlewares to the `Service`.
type Task ¶
type Task struct {
ID uuid.UUID `json:"id"` // ID is the id of the task
Priority int `json:"priority"` // Priority is the priority of the task
Fn func() interface{} `json:"-"` // Fn is the function that will be executed by the task
Ctx context.Context `json:"context"` // Ctx is the context of the task
Cancel context.CancelFunc `json:"-"` // Cancel is the cancel function of the task
Started atomic.Int64 `json:"started"` // Started is the time the task started
Completed atomic.Int64 `json:"completed"` // Completed is the time the task completed
Cancelled atomic.Int64 `json:"cancelled"` // Cancelled is the time the task was cancelled
}
Task represents a function that can be executed by the task manager
type TaskManager ¶
type TaskManager struct {
Registry sync.Map // Registry is a map of registerd tasks
Results chan interface{} // Results is the channel of results
// contains filtered or unexported fields
}
TaskManager is a struct that manages a pool of goroutines that can execute tasks
func (*TaskManager) CancelTask ¶
func (tm *TaskManager) CancelTask(id uuid.UUID)
CancelTask cancels a task by its ID
func (*TaskManager) GetResults ¶
func (tm *TaskManager) GetResults() <-chan interface{}
GetResults gets the results channel
func (*TaskManager) GetTask ¶
func (tm *TaskManager) GetTask(id uuid.UUID) (task Task, ok bool)
GetTask gets a task by its ID
func (*TaskManager) RegisterTask ¶
func (tm *TaskManager) RegisterTask(tasks ...Task)
RegisterTask registers a new task to the task manager
func (*TaskManager) Start ¶
func (tm *TaskManager) Start(numWorkers int)
Start starts the task manager and its goroutines
func (*TaskManager) Stop ¶
func (tm *TaskManager) Stop()
Stop stops the task manager and its goroutines
Click to show internal directories.
Click to hide internal directories.