pooltask

package
v0.0.0-...-503c688 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// PendingTask is a task waiting to start.
	PendingTask int32 = iota
	// RunningTask is a task running.
	RunningTask
	// StopTask is a stop task.
	StopTask
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context[T any] interface {
	GetContext() T
}

Context is a interface that can be used to create a context.

type GPool

type GPool[T any, U any, C any, CT any, TF Context[CT]] interface {
	Tune(size int32)
	DeleteTask(id uint64)
	StopTask(id uint64)
}

GPool is a goroutine pool.

type NilContext

type NilContext struct{}

NilContext is to create a nil as context

func (NilContext) GetContext

func (NilContext) GetContext() any

GetContext is to get a nil as context

type Task

type Task[T any] struct {
	Task T
}

Task is a task that can be executed.

type TaskBox

type TaskBox[T any, U any, C any, CT any, TF Context[CT]] struct {
	// contains filtered or unexported fields
}

TaskBox is a box which contains all info about pool task.

func NewTaskBox

func NewTaskBox[T any, U any, C any, CT any, TF Context[CT]](constArgs C, contextFunc TF, wg *sync.WaitGroup, taskCh chan Task[T], resultCh chan U, taskID uint64) TaskBox[T, U, C, CT, TF]

NewTaskBox is to create a task box for pool.

func (*TaskBox[T, U, C, CT, TF]) Clone

func (t *TaskBox[T, U, C, CT, TF]) Clone() *TaskBox[T, U, C, CT, TF]

Clone is to copy the box

func (*TaskBox[T, U, C, CT, TF]) ConstArgs

func (t *TaskBox[T, U, C, CT, TF]) ConstArgs() C

ConstArgs is to get the const args.

func (*TaskBox[T, U, C, CT, TF]) Done

func (t *TaskBox[T, U, C, CT, TF]) Done()

Done is to set the pooltask status to complete.

func (*TaskBox[T, U, C, CT, TF]) Finish

func (t *TaskBox[T, U, C, CT, TF]) Finish()

Finish is to set the TaskBox finish status.

func (*TaskBox[T, U, C, CT, TF]) GetContextFunc

func (t *TaskBox[T, U, C, CT, TF]) GetContextFunc() TF

GetContextFunc is to get context func.

func (*TaskBox[T, U, C, CT, TF]) GetResultCh

func (t *TaskBox[T, U, C, CT, TF]) GetResultCh() chan U

GetResultCh is to get result channel

func (*TaskBox[T, U, C, CT, TF]) GetStatus

func (t *TaskBox[T, U, C, CT, TF]) GetStatus() int32

GetStatus is to get the status of task.

func (*TaskBox[T, U, C, CT, TF]) GetTaskCh

func (t *TaskBox[T, U, C, CT, TF]) GetTaskCh() chan Task[T]

GetTaskCh is to get the task channel.

func (*TaskBox[T, U, C, CT, TF]) SetStatus

func (t *TaskBox[T, U, C, CT, TF]) SetStatus(s int32)

SetStatus is to set the status of task.

func (*TaskBox[T, U, C, CT, TF]) TaskID

func (t *TaskBox[T, U, C, CT, TF]) TaskID() uint64

TaskID is to get the task id.

type TaskController

type TaskController[T any, U any, C any, CT any, TF Context[CT]] struct {
	// contains filtered or unexported fields
}

TaskController is a controller that can control or watch the pool.

func NewTaskController

func NewTaskController[T any, U any, C any, CT any, TF Context[CT]](p GPool[T, U, C, CT, TF], taskID uint64, productExitCh chan struct{}, wg *sync.WaitGroup, inputCh chan Task[T], resultCh chan U) TaskController[T, U, C, CT, TF]

NewTaskController create a controller to deal with pooltask's status.

func (*TaskController[T, U, C, CT, TF]) Stop

func (t *TaskController[T, U, C, CT, TF]) Stop()

Stop is to send stop command to the task. But you still need to wait the task to stop.

func (*TaskController[T, U, C, CT, TF]) TaskID

func (t *TaskController[T, U, C, CT, TF]) TaskID() uint64

TaskID is to get the task id.

func (*TaskController[T, U, C, CT, TF]) Wait

func (t *TaskController[T, U, C, CT, TF]) Wait()

Wait is to wait the pool task to stop.

type TaskManager

type TaskManager[T any, U any, C any, CT any, TF Context[CT]] struct {
	// contains filtered or unexported fields
}

TaskManager is a manager that can control or watch the pool.

func NewTaskManager

func NewTaskManager[T any, U any, C any, CT any, TF Context[CT]](c int32) TaskManager[T, U, C, CT, TF]

NewTaskManager create a new pool task manager.

func (*TaskManager[T, U, C, CT, TF]) AddSubTask

func (t *TaskManager[T, U, C, CT, TF]) AddSubTask(taskID uint64, task *TaskBox[T, U, C, CT, TF])

AddSubTask AddTask add a task to the manager.

func (*TaskManager[T, U, C, CT, TF]) DeleteTask

func (t *TaskManager[T, U, C, CT, TF]) DeleteTask(taskID uint64)

DeleteTask delete a task from the manager.

func (*TaskManager[T, U, C, CT, TF]) Downclock

func (t *TaskManager[T, U, C, CT, TF]) Downclock(capacity int)

Downclock is to decrease the concurrency of pool.

func (*TaskManager[T, U, C, CT, TF]) ExitSubTask

func (t *TaskManager[T, U, C, CT, TF]) ExitSubTask(taskID uint64)

ExitSubTask is to exit a task, and it will decrease the count of running pooltask.

func (*TaskManager[T, U, C, CT, TF]) GetOriginConcurrency

func (t *TaskManager[T, U, C, CT, TF]) GetOriginConcurrency() int32

GetOriginConcurrency return the concurrency of the pool at the init.

func (*TaskManager[T, U, C, CT, TF]) Overclock

func (t *TaskManager[T, U, C, CT, TF]) Overclock(capacity int) (tid uint64, task *TaskBox[T, U, C, CT, TF])

Overclock is to increase the concurrency of pool.

func (*TaskManager[T, U, C, CT, TF]) RegisterTask

func (t *TaskManager[T, U, C, CT, TF]) RegisterTask(taskID uint64, concurrency int32)

RegisterTask register a task to the manager.

func (*TaskManager[T, U, C, CT, TF]) Running

func (t *TaskManager[T, U, C, CT, TF]) Running(taskID uint64) int32

Running return the count of running job in this task.

func (*TaskManager[T, U, C, CT, TF]) StopTask

func (t *TaskManager[T, U, C, CT, TF]) StopTask(taskID uint64)

StopTask is to stop a task by TaskID.

type TaskStatusContainer

type TaskStatusContainer[T any, U any, C any, CT any, TF Context[CT]] struct {
	// contains filtered or unexported fields
}

TaskStatusContainer is a container that can control or watch the pool.

Jump to

Keyboard shortcuts

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