Documentation
¶
Index ¶
- Variables
- func IsDevelFromContext(ctx context.Context) bool
- func MaintenanceFromContext(ctx context.Context) bool
- func NameFromContext(ctx context.Context) string
- func NewIsDevelContext(ctx context.Context, isDevel bool) context.Context
- func NewMaintenanceContext(ctx context.Context, isMaintenance bool) context.Context
- func NewNameContext(ctx context.Context, name string) context.Context
- type Func
- type LogPrintf
- type Logger
- type Manager
- func (cm *Manager) Add(name string, schedule Schedule, r Runner)
- func (cm *Manager) AddFunc(name string, schedule Schedule, fn Func)
- func (cm *Manager) AddMaintenanceFunc(name string, schedule Schedule, fn Func)
- func (cm *Manager) Handler(w http.ResponseWriter, r *http.Request)
- func (cm *Manager) ManualRun(ctx context.Context, id string) error
- func (cm *Manager) Run(ctx context.Context) error
- func (cm *Manager) State() States
- func (cm *Manager) Stop() context.Context
- func (cm *Manager) TextSchedule(w io.Writer)
- func (cm *Manager) Use(m ...MiddlewareFunc)
- type MiddlewareFunc
- func WithDevel(isDevel bool) MiddlewareFunc
- func WithLogger(pf LogPrintf, managerName string) MiddlewareFunc
- func WithMaintenance(p LogPrintf) MiddlewareFunc
- func WithMetrics(app string) MiddlewareFunc
- func WithRecover() MiddlewareFunc
- func WithSLog(lg Logger) MiddlewareFunc
- func WithSentry() MiddlewareFunc
- func WithSkipActive() MiddlewareFunc
- type Runner
- type Schedule
- type State
- type States
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsDevelFromContext ¶
IsDevelFromContext returns isDevel flag from context.
func MaintenanceFromContext ¶
func NameFromContext ¶
func NewIsDevelContext ¶
NewIsDevelContext creates new context with isDevel flag.
func NewMaintenanceContext ¶
Types ¶
type Logger ¶
type Logger interface {
Print(ctx context.Context, msg string, args ...any)
Error(ctx context.Context, msg string, args ...any)
}
Logger is as simple interface for slog.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a Cron manager with context and middleware support.
func NewManager ¶
func NewManager() *Manager
func (*Manager) AddMaintenanceFunc ¶
AddMaintenanceFunc adds func to cron.
func (*Manager) Run ¶
Run is a main function that registers all jobs and starts robfig/cron in separate goroutine.
func (*Manager) TextSchedule ¶
TextSchedule writes current cron schedule with TabWriter.
type MiddlewareFunc ¶
func WithDevel ¶
func WithDevel(isDevel bool) MiddlewareFunc
WithDevel sets bool flag to context for detecting development environment.
func WithLogger ¶
func WithLogger(pf LogPrintf, managerName string) MiddlewareFunc
WithLogger logs via Printf function (e.g. log.Printf) all runs.
func WithMaintenance ¶
func WithMaintenance(p LogPrintf) MiddlewareFunc
WithMaintenance puts cron jobs in line, got exclusive lock for maintenance job.
func WithMetrics ¶
func WithMetrics(app string) MiddlewareFunc
WithMetrics tracks total/active/duration metrics for runs.
func WithRecover ¶
func WithRecover() MiddlewareFunc
WithRecover use recover() func. Do not use with WithSentry middleware due to recover() call.
func WithSLog ¶
func WithSLog(lg Logger) MiddlewareFunc
WithSLog logs all runs via slog (see Logger interface).
func WithSentry ¶
func WithSentry() MiddlewareFunc
WithSentry sends all errors to sentry. It's also handles panics.
func WithSkipActive ¶
func WithSkipActive() MiddlewareFunc
WithSkipActive skips funcs if they are already running.
