Documentation ¶
Index ¶
- Variables
- func GetParam(ctx SchedulerContext) (any, error)
- func GetTaskId(ctx SchedulerContext) (string, error)
- func GetWorkId(ctx SchedulerContext) (string, error)
- type MiddlewareApplicator
- type MiddlewareFunc
- type Option
- type PlainContext
- type ScheduleHandlerFn
- type Scheduler
- type SchedulerContext
- func BuildContext(scheduledTime time.Time, workFn WorkFn, valMap map[any]any, options ...Option) SchedulerContext
- func NewPlainContext(scheduledTime time.Time, workFn WorkFn, values map[any]any) SchedulerContext
- func WrapContext(parent SchedulerContext, options ...Option) (ctx SchedulerContext)
- func WrapWithParam(parent SchedulerContext, param any) SchedulerContext
- func WrapWithParamLoader(parent SchedulerContext, loader func() (any, error)) SchedulerContext
- func WrapWithTaskId(parent SchedulerContext, taskId string) SchedulerContext
- func WrapWithWorkFn(parent SchedulerContext, workFn WorkFn) SchedulerContext
- func WrapWithWorkFnWrapper(parent SchedulerContext, wrapper WorkFnWrapper) SchedulerContext
- func WrapWithWorkId(parent SchedulerContext, workId string) SchedulerContext
- type Task
- type WorkFn
- type WorkFnWParam
- type WorkFnWrapper
Constants ¶
This section is empty.
Variables ¶
var (
ErrValueNotFound = errors.New("value not found")
)
Functions ¶
func GetParam ¶
func GetParam(ctx SchedulerContext) (any, error)
func GetTaskId ¶
func GetTaskId(ctx SchedulerContext) (string, error)
GetTaskId gets task id from ctx. This may be heavy or cause error. If task id is not set, GetTaskId returns a wrapped ErrValueNotFound.
func GetWorkId ¶
func GetWorkId(ctx SchedulerContext) (string, error)
GetWorkId gets task id from ctx. This may be heavy or cause error. If work id is not set, GetWorkId returns a wrapped ErrValueNotFound.
Types ¶
type MiddlewareApplicator ¶
type MiddlewareApplicator[T Scheduler] struct { // contains filtered or unexported fields }
func NewMiddlewareApplicator ¶
func NewMiddlewareApplicator[T Scheduler](scheduler T) *MiddlewareApplicator[T]
func (*MiddlewareApplicator[T]) Schedule ¶
func (s *MiddlewareApplicator[T]) Schedule(ctx SchedulerContext) (Task, error)
Schedule schedules ctx to inner scheduler with middlewares applied. Middlewares will be called in first-in-first-applied order.
func (*MiddlewareApplicator[T]) Scheduler ¶
func (ma *MiddlewareApplicator[T]) Scheduler() T
Scheduler is getter of inner sheculer.
func (*MiddlewareApplicator[T]) Use ¶
func (s *MiddlewareApplicator[T]) Use(mw ...MiddlewareFunc)
Use registers MiddlewareFunc. First registered one will be invoked first.
type MiddlewareFunc ¶
type MiddlewareFunc = func(handler ScheduleHandlerFn) ScheduleHandlerFn
type Option ¶
type Option func(ctx SchedulerContext) SchedulerContext
func WithParamLoader ¶
func WithTaskId ¶
func WithWorkFn ¶
func WithWorkFnWrapper ¶
func WithWorkFnWrapper(wrapper WorkFnWrapper) Option
func WithWorkId ¶
type PlainContext ¶
type PlainContext struct {
// contains filtered or unexported fields
}
PlainContext is intended to be a base context of SchedulerContext.
func (*PlainContext) ScheduledTime ¶
func (ctx *PlainContext) ScheduledTime() time.Time
func (*PlainContext) Work ¶
func (ctx *PlainContext) Work() WorkFn
type ScheduleHandlerFn ¶
type ScheduleHandlerFn = func(ctx SchedulerContext) (Task, error)
type Scheduler ¶
type Scheduler interface {
Schedule(task *scheduler.Task) (*scheduler.TaskController, error)
}
type SchedulerContext ¶
type SchedulerContext interface { ScheduledTime() time.Time Work() WorkFn Value(key any) (any, error) }
SchedulerContext is minimal set of data relevant to scheduling and middlewares.
func BuildContext ¶
func BuildContext(scheduledTime time.Time, workFn WorkFn, valMap map[any]any, options ...Option) SchedulerContext
BuildContext builds a new SchedulerContext. workFn, valMap can be nil. Add options to set additional values to the ctx.
func NewPlainContext ¶
NewPlainContext creates a new PlainContext instance. But recommendation here is to use BuildContext instead.
func WrapContext ¶
func WrapContext(parent SchedulerContext, options ...Option) (ctx SchedulerContext)
WrapContext wrapps parent with options.
func WrapWithParam ¶
func WrapWithParam(parent SchedulerContext, param any) SchedulerContext
func WrapWithParamLoader ¶
func WrapWithParamLoader(parent SchedulerContext, loader func() (any, error)) SchedulerContext
func WrapWithTaskId ¶
func WrapWithTaskId(parent SchedulerContext, taskId string) SchedulerContext
func WrapWithWorkFn ¶
func WrapWithWorkFn(parent SchedulerContext, workFn WorkFn) SchedulerContext
func WrapWithWorkFnWrapper ¶
func WrapWithWorkFnWrapper(parent SchedulerContext, wrapper WorkFnWrapper) SchedulerContext
func WrapWithWorkId ¶
func WrapWithWorkId(parent SchedulerContext, workId string) SchedulerContext
type WorkFnWParam ¶
type WorkFnWrapper ¶
type WorkFnWrapper = func(self SchedulerContext, workFn WorkFn) WorkFn
Directories ¶
Path | Synopsis |
---|---|
Package mock_gokugen is a generated GoMock package.
|
Package mock_gokugen is a generated GoMock package. |
__mock
Package mock_common is a generated GoMock package.
|
Package mock_common is a generated GoMock package. |
__mock
Package mock_cron is a generated GoMock package.
|
Package mock_cron is a generated GoMock package. |
example
|
|
impl
|
|
middleware
|
|
log/__mock
Package mock_log is a generated GoMock package.
|
Package mock_log is a generated GoMock package. |