cron

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 6 Imported by: 1

README

cron

A Lightweight Cron Module

Install

go get github.com/frisbm/cron

Usage

package main

import (
	"fmt"
	"github.com/frisbm/cron"
	"log"
)

func main() {
	cron, err := cron.Parse("* * * * *")
	if err != nil {
		log.Fatal(err)
	}

	now := cron.Now()
	fmt.Println(now) // true
}

See package documentation here

Example

See an example cron scheduler service in scheduler module

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyCronSchedule   = errors.New("cron schedule is empty")
	InvalidCronSchedule = errors.New("invalid cron schedule")
)

Functions

This section is empty.

Types

type Cron

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

Cron represents the cron schedule

func Parse

func Parse(schedule string) (*Cron, error)

Parse takes a standard cron schedule (* * * * *) and returns a Cron object if the schedule is valid; otherwise, it returns an error. It uses goroutines to parse each part of the schedule concurrently, resulting in faster parsing.

The schedule follows the standard format:

* [0-59] (* , / -)

* [0-23] (* , / -)

* [1-31] (* , / -)

* [1-12] (* , / -)

* [0-6] (* , / -)

func (*Cron) Next

func (c *Cron) Next() time.Time

Next will return the next cron activation after now

func (*Cron) NextFrom

func (c *Cron) NextFrom(from time.Time) time.Time

NextFrom accepts a time in which it will calculate the next activation time after

func (*Cron) Now

func (c *Cron) Now() bool

Now will tell you it is currently time for a cron schedule to activate

func (*Cron) Prev

func (c *Cron) Prev() time.Time

Prev will return the previous cron activation before now

func (*Cron) PrevBefore

func (c *Cron) PrevBefore(before time.Time) time.Time

PrevBefore accepts a time in which it will calculate the previous activation time before now

func (*Cron) UseLocal

func (c *Cron) UseLocal()

UseLocal will set the cron schedule calculations to use the local time of the system it is running on

Directories

Path Synopsis
scheduler module

Jump to

Keyboard shortcuts

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