Documentation ¶
Overview ¶
Example (NewButcher_Options) ¶
ctx := context.Background() executor := &basicExecutor{} b, err := NewButcher( executor, MaxWorker(3), // specifies maximum number of concurrent workers, default is 1. BufferSize(20), // specifies job buffer size, recommended value is bigger than MaxWorker and RateLimit, default is 1. RateLimit(10.0), // control task execute speed, default is Infinity. TaskTimeout(1*time.Second), // specifies task execute timeout, returns a context.TimeExceeded error if timeout is exceeded, default no timeout. RetryOnError(3), // specifies retry times when task return error, default no retry. InterruptSignal(syscall.SIGINT, syscall.SIGTERM), // specified signals can interrupt task running, default is syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT. ) if err != nil { panic(err) } err = b.Run(ctx) if err != nil { panic(err) } fmt.Println("all done")
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface { // GenerateJob generate your jobs here. put your job into jobCh, don't close jobCh manually. GenerateJob(ctx context.Context, jobCh chan<- interface{}) error // Task execute your job here. It will be scheduled by butcher. Task(ctx context.Context, job interface{}) error }
Executor implements task executor interface.
type OnFinishWatcher ¶
OnFinishWatcher implements optional OnFinish function if you want to watch the result of job.
type Option ¶
type Option func(b *butcher) error
func BufferSize ¶
BufferSize specifies job buffer size, recommended value is bigger than MaxWorker and RateLimit, default is 1.
func InterruptSignal ¶ added in v0.1.0
InterruptSignal specified signals can interrupt task running. Default is syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT.
func RetryOnError ¶
RetryOnError specifies retry times when task return error, default no retry.
func TaskTimeout ¶ added in v0.1.0
TaskTimeout specifies task execute timeout, returns a context.TimeExceeded error if timeout is exceeded, default no timeout.
Click to show internal directories.
Click to hide internal directories.