schedule

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Example (JobFunc)
someJob := func(cancel <-chan struct{}) error {
	fin := make(chan struct{})
	go func() {
		// do some work
		close(fin)
	}()
	select {
	case <-fin:
		// job finished normally
	case <-cancel:
		// job canceled, do some cancelling work
	}
	return nil
}
someJob(nil)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixedDelayTask

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

func (*FixedDelayTask) MustStart

func (t *FixedDelayTask) MustStart()

func (*FixedDelayTask) MustStop

func (t *FixedDelayTask) MustStop()

func (*FixedDelayTask) Name

func (t *FixedDelayTask) Name() string

func (*FixedDelayTask) Start

func (t *FixedDelayTask) Start() error

func (*FixedDelayTask) Stop

func (t *FixedDelayTask) Stop() error

type FixedRateTask

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

func (*FixedRateTask) MustStart

func (t *FixedRateTask) MustStart()

func (*FixedRateTask) MustStop

func (t *FixedRateTask) MustStop()

func (*FixedRateTask) Name

func (t *FixedRateTask) Name() string

func (*FixedRateTask) Start

func (t *FixedRateTask) Start() error

func (*FixedRateTask) Stop

func (t *FixedRateTask) Stop() error

type JobFunc

type JobFunc func(cancel <-chan struct{}) error

User defined job. It's recommended that JobFunc respond to cancel channel.

type Task

type Task interface {
	// Return the Task name
	Name() string
	// Start the Task, cannot start a Task twice or start a stopped Task
	Start() error
	// Start the Task, panic if error happened
	MustStart()
	// Stop the task, cannot stop a not started Task or stop a Task twice.
	// This function only send the stop signal to the Task, does not wait for JobFunc to finish.
	Stop() error
	// Stop the Task, panic if error happened
	MustStop()
}

func NewFixedDelayTask

func NewFixedDelayTask(name string, job JobFunc, interval time.Duration, timeout time.Duration) Task

Create a new FixedDelayTask.

Run jobs after another when previous one finished and interval time elapsed.

func NewFixedRateTask

func NewFixedRateTask(name string, job JobFunc, interval time.Duration, timeout time.Duration) Task

Create a new FixedRateTask.

Run jobs at a fixed rate. Be careful that if interval <= timeout, or job does not respond to cancel channel (see JobFunc), jobs may be overlapped.

type TaskManager

type TaskManager interface {
	// Register a Task and start it.
	// Once the Task is managed by TaskManager, you should not call Task
	// lifecycle function(Task.Stop, Task.Start) any more.
	Register(task Task) error
	// Call Task.Stop and unregister it
	// This function only send the stop signal to Task(s), returning doesn't mean JobFunc is stopped
	Unregister(name string)
	// Stop all the Task and unregister them
	UnregisterAll()
}

Task manager

func NewTaskManager

func NewTaskManager() TaskManager

Jump to

Keyboard shortcuts

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