Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackgroundTaskManager ¶
type BackgroundTaskManager struct {
// contains filtered or unexported fields
}
BackgroundTaskManager is a task manager which manages prioritized tasks and background tasks execution. Background tasks are less important than prioritized tasks. You can let these background tasks not to use compute resources (CPU, NW, etc...) during more important tasks(=prioritized tasks) running.
When you run a prioritised task and don't want background tasks to use resources you can tell it this manager by calling DoPrioritizedTask method. DonePrioritizedTask method must be called at the end of the prioritised task execution.
For running a background task, you can use InvokeBackgroundTask method. The background task must be able to be cancelled via context.Context argument. The task is forced to wait until no prioritized task is running for some period. You can specify the period when making this manager instance. The limited number of background tasks run simultaneously and you can specify the concurrency when making this manager instance too. If a prioritized task starts during the execution of background tasks, all background tasks running will be cancelled via context. These cancelled tasks will be executed again later, same as other background tasks (when no prioritized task is running for some period).
func NewBackgroundTaskManager ¶
func NewBackgroundTaskManager(concurrency int64, period time.Duration) *BackgroundTaskManager
NewBackgroundTaskManager provides a task manager. You can specify the concurrency of background tasks. When running a background task, this will be forced to wait until no prioritized task is running for some period. You can specify the period through the argument of this function, too.
func (*BackgroundTaskManager) DoPrioritizedTask ¶
func (ts *BackgroundTaskManager) DoPrioritizedTask()
DoPrioritizedTask tells the manager that we are running a prioritized task and don't want background tasks to disturb resources(CPU, NW, etc...)
func (*BackgroundTaskManager) DonePrioritizedTask ¶
func (ts *BackgroundTaskManager) DonePrioritizedTask()
DonePrioritizedTask tells the manager that we've done a prioritized task and don't want background tasks to disturb resources(CPU, NW, etc...)
func (*BackgroundTaskManager) InvokeBackgroundTask ¶
func (ts *BackgroundTaskManager) InvokeBackgroundTask(do func(context.Context), timeout time.Duration)
InvokeBackgroundTask invokes a background task. The task is started only when no prioritized tasks are running. Prioritized task's execution stops the execution of all background tasks. Background task must be able to be cancelled via context.Context argument and be able to be restarted again.