cronz

package module
v0.0.0-...-2d28c6b Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action = middleware.Handler[Context]

type Context

type Context interface {
	context.Context
	Name() string
	Spec() string
	RunID() string
	WithContext(context.Context) Context
}

type Middleware

type Middleware = middleware.Middleware[Context]

func Logging

func Logging(logger *slog.Logger) Middleware

Logging creates a middleware that adds detailed logging.

func Metrics

func Metrics() Middleware

Metrics creates a middleware that collects job execution metrics.

func Recovery

func Recovery(logger *slog.Logger, stack bool) Middleware

Recovery creates a middleware that recovers from panics.

func Timeout

func Timeout(timeout time.Duration) Middleware

Timeout creates a middleware that adds a timeout to job execution.

func Trace

func Trace(tracerName string) Middleware

Trace creates a middleware that adds OpenTelemetry tracing.

type Option

type Option func(s *Server)

Option is the new server option.

func WithCronOptions

func WithCronOptions(opts ...cron.Option) Option

WithCronOptions sets the cron options.

func WithLogger

func WithLogger(log *slog.Logger) Option

WithLogger sets the logger.

func WithMiddlewares

func WithMiddlewares(mws ...Middleware) Option

WithMiddlewares adds middleware to the cron server.

type Server

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

Server is a cron server which implements kraots [transport.Server].

func New

func New(opts ...Option) *Server

New creates a new instance of the cron server.

func (*Server) Register

func (s *Server) Register(
	name string,
	spec string,
	action Action,
) error

Register registers a job by specifying its name, spec and action.

func (*Server) Start

func (cs *Server) Start(ctx context.Context) error

Start starts the cron scheduler. It will run all registered jobs according to their schedule. This method is a blocking call and will not return until the scheduler is stopped.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop stops the cron scheduler. It waits for all running jobs to finish before returning. If a job is running long, it will return an error. This is a blocking call.

If you want to stop the cron server without waiting for jobs to finish, you can use a separate context with a timeout or cancellation. This will stop the cron server immediately without waiting for jobs to finish.

func (*Server) Use

func (s *Server) Use(mws ...Middleware)

Use adds middleware to the cron server

Jump to

Keyboard shortcuts

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