task

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyOptions = func() *Options {
	return &Options{
		Singleton: false,
		Argument:  nil,
	}
}

Functions

func ContextWithTaskService

func ContextWithTaskService(ctx context.Context) context.Context

func RegisterImplementor

func RegisterImplementor(c Task)

RegisterImplementor registers the task service implementor.

func RegisterLockerImplementor

func RegisterLockerImplementor(locker Locker)

RegisterLockerImplementor registers the task locker service implementor.

func StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor for crontab task.

func UnaryServerInterceptor

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor for crontab task.

Types

type Executor

type Executor interface {
	Execute(context.Context, interface{}) error
}

type ExecutorFunc

type ExecutorFunc func(ctx context.Context, arg interface{}) error

func (ExecutorFunc) Execute

func (fn ExecutorFunc) Execute(ctx context.Context, arg interface{}) error

type Locker

type Locker interface {
	// Lock tries to get the locker of the scheduler,
	// should be blocked before acquired the locker.
	Lock(ctx context.Context, scheduler string) context.Context
	// Unlock gives up the schedule locker.
	Unlock(scheduler string)
}

Locker interface.

func LockerImplementor

func LockerImplementor() Locker

LockerImplementor return the task locker service implementor.

type Option

type Option func(options *Options)

func WithArgument

func WithArgument(arg interface{}) Option

func WithComponent

func WithComponent(component string) Option

func WithName

func WithName(name string) Option

func WithProduct

func WithProduct(product string) Option

func WithSingleton

func WithSingleton() Option

type Options

type Options struct {
	Component string
	Product   string
	Name      string
	Singleton bool
	Argument  interface{}
}

type Task

type Task interface {
	// Schedule a task.
	// Supported spec, refer: https://github.com/robfig/cron/tree/v3.0.1
	Schedule(spec string, exec Executor, opts ...Option) error
}

func ContextTaskService

func ContextTaskService(ctx context.Context) Task

func Implementor

func Implementor() Task

Implementor returns the task service implementor.

Jump to

Keyboard shortcuts

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