cron

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 7 Imported by: 1

README

Cron - Make Job Scheduling Easier

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/cron

Getting Started

import (
  "testing"
  "github.com/go-zoox/cron"
)

func main(t *testing.T) {
	c, err := cron.New()
	if err != nil {
		t.Fatal(err)
	}

	// c.AddJob("*/1 * * * *", func() {
	// 	t.Log("cron job ran at", time.Now())
	// })

	c.AddSecondlyJob(func() {
		t.Log("cron job ran at", time.Now())
	})

	c.Start()

	for {
		time.Sleep(time.Second)
	}
}

Inspired by

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.2.2"

Version is the current version of cron.

Functions

This section is empty.

Types

type AddJobConfig added in v1.2.2

type AddJobConfig struct {
	// RunRightNow specifies whether to run the job immediately after adding it.
	RunRightNow bool
}

AddJobConfig is a configuration for AddJob.

type AddJobOption added in v1.2.2

type AddJobOption func(cfg *AddJobConfig)

AddJobOption is a function that configures the AddJob.

type Config

type Config struct {
	// TimeZone is the timezone in which the cron will run.
	TimeZone string

	// RunNow specifies whether to run the job immediately after adding it.
	RunRightNow bool
}

Config is a wrapper of robCron.Config

type Cron

type Cron struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Cron is a schedule job, which can be used to run jobs on a schedule.

func New

func New(cfg ...*Config) (*Cron, error)

New creates a new Cron with the given configuration.

func (*Cron) AddDailyJob

func (c *Cron) AddDailyJob(id string, cmd func() error) (err error)

AddDailyJob adds a schedule job run in every day.

func (*Cron) AddHourlyJob

func (c *Cron) AddHourlyJob(id string, cmd func() error) (err error)

AddHourlyJob adds a schedule job run in every hour.

func (*Cron) AddJob

func (c *Cron) AddJob(id string, spec string, job func() error, opts ...AddJobOption) error

AddJob adds a Job to the Cron to be run on the given schedule.

func (*Cron) AddMinutelyJob

func (c *Cron) AddMinutelyJob(id string, cmd func() error) (err error)

AddMinutelyJob adds a schedule job run in every minute.

func (*Cron) AddMonthlyJob

func (c *Cron) AddMonthlyJob(id string, cmd func() error) (err error)

AddMonthlyJob adds a schedule job run in every month.

func (*Cron) AddSecondlyJob

func (c *Cron) AddSecondlyJob(id string, cmd func() error) (err error)

AddSecondlyJob adds a schedule job run in every second.

func (*Cron) AddWeeklyJob

func (c *Cron) AddWeeklyJob(id string, cmd func() error) (err error)

AddWeeklyJob adds a schedule job run in every week.

func (*Cron) AddYearlyJob

func (c *Cron) AddYearlyJob(id string, cmd func() error) (err error)

AddYearlyJob adds a schedule job run in every year.

func (*Cron) Clear added in v1.1.2

func (c *Cron) Clear() (err error)

Clear clears the cron scheduler jobs.

func (*Cron) ClearJobs added in v1.1.0

func (c *Cron) ClearJobs() (err error)

ClearJobs clears all jobs.

func (*Cron) HasJob added in v1.2.0

func (c *Cron) HasJob(id string) bool

HasJob returns true if the given job exists.

func (*Cron) Length added in v1.1.0

func (c *Cron) Length() int

Length returns the number of jobs in the given schedule.

func (*Cron) RemoveJob added in v1.1.0

func (c *Cron) RemoveJob(id string) (err error)

RemoveJob removes a Job from the Cron to be run on the given schedule.

func (*Cron) Restart added in v1.1.0

func (c *Cron) Restart() (err error)

Restart starts the cron scheduler in a new goroutine.

func (*Cron) Start

func (c *Cron) Start() (err error)

Start starts the cron scheduler in a new goroutine.

func (*Cron) Stop

func (c *Cron) Stop() (err error)

Stop stops the cron scheduler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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