jobber

package
v0.0.0-...-1ad5891 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 5 Imported by: 0

README

jobber

Time Strings

Field time specifies the schedule at which a job is run, in a manner similar to how cron jobs’ schedules are specified: with a space-separated list of up to six specifiers, each one of which constrains a different component of time (second, minute, hour, etc.). Schematically:

sec min hour month_day month week_day

A job is scheduled thus: it will run at any time that satisfies all of the specifiers sec, min, hour, and month and one of the specifiers month_day and week_day.

Each specifier can take one of the following forms: ("a", "b", "c", and "n" are placeholders for arbitrary numerals.)

Specifier Form What It Matches
* Any value
a The value a
*/n Every n-th value — e.g., */25 in the sec specifier would match 0, 25, and 50, whereas in the month specifier it would match 1 and 26.
a,b,c,... The values a, b, c, ...
a-b Any of the values between and including a and b

The specifiers have different permitted values for the placeholders in the specifier forms:

Specifier Values for “a”, “b”, and “c” Values for "n"
sec 0 thru 59 1 thru 59
min 0 thru 59 1 thru 59
hour 0 thru 23 1 thru 23
month_day 1 thru 31 1 thru 30
month 1 thru 12 1 thru 11
week_day 0 thru 6 1 thru 5

NOTE: Because in a YAML document * has a special meaning at the beginning of an item, if your time string starts with * you must quote the whole string, thus: time: '*/10'.

Documentation

Overview

Package jobber time strings parser from jobber

Example (Simple)
package main

import (
	"fmt"
	"time"

	"github.com/Akagi201/utilgo/jobber"
)

func main() {
	timeStr := "*/2 * * * * *"

	res, err := jobber.ParseFullTimeSpec(timeStr)
	if err != nil {
		fmt.Errorf("Parse time string failed, err: %v\n", err)
		return
	}

	fmt.Printf("Time string: %v\n", res.String())

	now := time.Now()
	fmt.Printf("now: %v, next: %v\n", now, res.Next(now))
}
Output:

Index

Examples

Constants

View Source
const (
	TimeWildcard = "*"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FullTimeSpec

type FullTimeSpec struct {
	Sec  TimeSpec
	Min  TimeSpec
	Hour TimeSpec
	Mday TimeSpec
	Mon  TimeSpec
	Wday TimeSpec
}

func ParseFullTimeSpec

func ParseFullTimeSpec(s string) (*FullTimeSpec, error)

func (FullTimeSpec) Next

func (self FullTimeSpec) Next(now time.Time) time.Time

func (FullTimeSpec) String

func (self FullTimeSpec) String() string

type OneValTimeSpec

type OneValTimeSpec struct {
	Val int
}

func (OneValTimeSpec) Satisfied

func (s OneValTimeSpec) Satisfied(v int) bool

func (OneValTimeSpec) String

func (s OneValTimeSpec) String() string

type SetTimeSpec

type SetTimeSpec struct {
	Desc string
	Vals []int
}

func (SetTimeSpec) Satisfied

func (s SetTimeSpec) Satisfied(v int) bool

func (SetTimeSpec) String

func (s SetTimeSpec) String() string

type TimeSpec

type TimeSpec interface {
	String() string
	Satisfied(int) bool
}

type WildcardTimeSpec

type WildcardTimeSpec struct {
}

func (WildcardTimeSpec) Satisfied

func (s WildcardTimeSpec) Satisfied(v int) bool

func (WildcardTimeSpec) String

func (s WildcardTimeSpec) String() string

Jump to

Keyboard shortcuts

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