service

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package service provides top level scheduler. Combined all elements (cron, resumer and crontab updater) together

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

type Cron interface {
	Start()
	Stop() context.Context
	Entries() []cron.Entry
	Schedule(schedule cron.Schedule, cmd cron.Job) cron.EntryID
	Remove(id cron.EntryID)
}

Cron interface defines basic robfig/cron methods used by service

type CrontabParser

type CrontabParser interface {
	String() string
	List() (result []crontab.JobSpec, err error)
	Changes(ctx context.Context) (<-chan []crontab.JobSpec, error)
}

CrontabParser interface loads the list of jobs and provides updates channel if the corresponding crontab file updated

type DayParser

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

DayParser for command line containing template elements from tmpl, like {{.YYYYMMDD}} replaces all occurrences of such templates. Handles business day detection for templates including "EOD" (i.e. YYYYMMDDEOD).

func NewDayTemplate

func NewDayTemplate(ts time.Time, options ...Option) *DayParser

NewDayTemplate makes day parser for given date

func (DayParser) Parse

func (p DayParser) Parse(dayTemplate string) (string, error)

Parse translate template to final string

type DeDup added in v0.2.0

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

DeDup implements thread safe map to register/unregister command in order to prevent dbl registration

func NewDeDup added in v0.2.0

func NewDeDup(enabled bool) *DeDup

NewDeDup creates DeDup. Object safe to use with default params (disabled)

func (*DeDup) Add added in v0.2.0

func (d *DeDup) Add(key string) bool

Add key to the map, fail if already in

func (*DeDup) Remove added in v0.2.0

func (d *DeDup) Remove(key string)

Remove key from the map. Safe to call multiple times

type Dedupper added in v0.4.0

type Dedupper interface {
	Add(key string) bool
	Remove(key string)
}

Dedupper defines a locking primitive to register/unregister command in order to prevent dbl registration

type ErrorWriter

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

ErrorWriter implements error and collect log messages. Not thread safe

func NewErrorWriter

func NewErrorWriter(maximum int) *ErrorWriter

NewErrorWriter makes io.Writer and error capturing data in and limit to last max lines

func (*ErrorWriter) Error

func (e *ErrorWriter) Error() string

Error returns string combining the error and log

func (*ErrorWriter) SerError

func (e *ErrorWriter) SerError(err error)

SerError assign error

func (*ErrorWriter) Write

func (e *ErrorWriter) Write(p []byte) (n int, err error)

Write satisfies io.Writer to collect last N log lines

type HolidayChecker

type HolidayChecker interface {
	IsHoliday(day time.Time) bool
}

HolidayChecker is a single-method interface returning status of the day

type HolidayCheckerFunc

type HolidayCheckerFunc func(day time.Time) bool

HolidayCheckerFunc is an adapter to allow the use of ordinary functions as HolidayChecker.

func (HolidayCheckerFunc) IsHoliday

func (h HolidayCheckerFunc) IsHoliday(day time.Time) bool

IsHoliday checks if the day is a holiday

type LogPrefixer added in v0.2.0

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

LogPrefixer implements `io.writer` interface and adds prefix to each output line.

func NewLogPrefixer added in v0.2.0

func NewLogPrefixer(writer io.Writer, command string) *LogPrefixer

NewLogPrefixer initializes log prefixer.

func (*LogPrefixer) Write added in v0.2.0

func (p *LogPrefixer) Write(data []byte) (int, error)

type Notifier

type Notifier interface {
	Send(ctx context.Context, subj, text string) error
	IsOnError() bool
	IsOnCompletion() bool
	MakeErrorHTML(spec, command, errorLog string) (string, error)
	MakeCompletionHTML(spec, command string) (string, error)
}

Notifier interface defines notification delivery on failed executions

type Option

type Option func(l *DayParser)

Option func type

func EndOfDay

func EndOfDay(hour int) Option

EndOfDay sets threshold time defining end of the business day

func Holiday

func Holiday(checker HolidayChecker) Option

Holiday sets a checker detecting if the current day is a holiday. Used for business days related logic.

func SkipWeekDays

func SkipWeekDays(days ...time.Weekday) Option

SkipWeekDays sets a list of weekdays to skip in detection of the current, next and prev. business days

func TimeZone

func TimeZone(tz *time.Location) Option

TimeZone sets timezone used for all time parsings

type Repeater added in v0.4.0

type Repeater interface {
	Do(ctx context.Context, fun func() error, errors ...error) (err error)
}

Repeater repeats failed function

type Resumer

type Resumer interface {
	OnStart(cmd string) (string, error)
	OnFinish(fname string) error
	List() (res []resumer.Cmd)
	String() string
}

Resumer defines interface for resumer.Resumer providing auto-restart for failed jobs

type Schedule added in v0.4.0

type Schedule interface {
	Next(time.Time) time.Time
}

Schedule describes a job's duty cycle.

type Scheduler

type Scheduler struct {
	Cron
	Resumer           Resumer
	ResumeConcurrency int
	CrontabParser     CrontabParser
	UpdatesEnabled    bool
	Jitter            time.Duration
	Notifier          Notifier
	DeDup             Dedupper
	HostName          string
	MaxLogLines       int
	EnableLogPrefix   bool
	Repeater          Repeater
	Stdout            io.Writer
	NotifyTimeout     time.Duration
}

Scheduler is a top-level service wiring cron, resumer ans parser and provifing the main entry point (blocking) to start the process

func (*Scheduler) Do

func (s *Scheduler) Do(ctx context.Context)

Do runs blocking scheduler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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