service

package
Version: v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: MIT Imports: 19 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 ErrorWriter

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

ErrorWriter implements error and collect log messages. Not thread safe

func NewErrorWriter

func NewErrorWriter(max 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(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 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 Scheduler

type Scheduler struct {
	Cron
	Resumer         Resumer
	CrontabParser   CrontabParser
	UpdatesEnabled  bool
	JitterEnabled   bool
	Notifier        Notifier
	DeDup           *DeDup
	HostName        string
	MaxLogLines     int
	EnableLogPrefix bool
	Repeater        *repeater.Repeater
	Stdout          io.Writer
}

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL