schedule

package
v1.0.35 Latest Latest
Warning

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

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

Documentation

Overview

Package schedule is to help you manage schedule tasks.

Example
package main

import (
	"github.com/boxgo/box"
	"github.com/boxgo/box/pkg/logger"
	"github.com/boxgo/box/pkg/schedule"
)

func main() {
	onceHandler := func(args map[string]interface{}) error {
		logger.Info("once handler executing...", args)
		return nil
	}

	timingHandler := func(args map[string]interface{}) error {
		logger.Info("timing handler executing...", args)
		return nil
	}

	sch := schedule.StdConfig("default").Build(schedule.WithHandler(onceHandler, timingHandler))

	app := box.New(
		box.WithBoxes(sch),
	)

	if err := app.Run(); err != nil {
		logger.Fatal(err)
	}
}
Output:

Index

Examples

Constants

View Source
const (
	Stop          = Type(0)
	Once          = Type(1)
	Timing        = Type(2)
	OnceAndTiming = Type(3)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgsKey added in v1.0.20

type ArgsKey struct{}

type Config

type Config struct {
	Type        Type                   `config:"type" desc:"Stop: 0, Once: 1, Timing: 2, OnceAndTiming: 3"`
	Spec        string                 `config:"spec" desc:"Cron spec info"`
	Specs       []string               `config:"specs" desc:"Multi cron spec info, higher priority than spec"`
	Compete     bool                   `config:"compete" desc:"Only winner can exec schedule"`
	AutoUnlock  bool                   `config:"autoUnlock" desc:"Auto unlock after task finish"`
	LockSeconds int                    `config:"lockSeconds" desc:"Lock ttl"`
	Delay       time.Duration          `config:"delay" desc:"Delay duration"`
	Timeout     time.Duration          `config:"timeout" desc:"Execute timeout, default 6h"`
	Args        map[string]interface{} `config:"args" desc:"Schedule arguments"`
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig(key string) *Config

func StdConfig

func StdConfig(key string) *Config

func (*Config) Build

func (c *Config) Build(optionFunc ...OptionFunc) *Schedule

func (*Config) Path

func (c *Config) Path() string

type Handler

type Handler func(ctx context.Context) error

type Journal added in v1.0.15

type Journal struct {
	Config    Config
	StartTime time.Time
	EndTime   time.Time
	Error     error
	Panic     interface{}
}

type OptionFunc

type OptionFunc func(*Config)

func WithHandler

func WithHandler(onceHandler, timingHandler Handler) OptionFunc

func WithLocker

func WithLocker(locker locker.MutexLocker) OptionFunc

func WithRecorder added in v1.0.15

func WithRecorder(recorder Recorder) OptionFunc

func WithServer added in v1.0.25

func WithServer(server *ginserver.GinServer) OptionFunc

type Recorder added in v1.0.15

type Recorder func(Journal)

type Schedule

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

Schedule instance is a server, you should mount bo box application to manage lifecycle.

func (*Schedule) ExecOnce

func (sch *Schedule) ExecOnce()

ExecOnce exec once handler immediately

func (*Schedule) ExecTiming

func (sch *Schedule) ExecTiming()

ExecTiming exec timing handler immediately

func (*Schedule) Name

func (sch *Schedule) Name() string

func (*Schedule) Serve

func (sch *Schedule) Serve(context.Context) error

Serve schedule

func (*Schedule) Shutdown

func (sch *Schedule) Shutdown(context.Context) error

Shutdown stop cron

type Type

type Type int

Jump to

Keyboard shortcuts

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