repeat

package
v0.0.0-...-fb49ba0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package repeat provides a system to run functions repeated on a schedule.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

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

Cron is a cron schedule.

func ParseCron

func ParseCron(s string) (*Cron, error)

ParseCron parses a crontab line into a Cron.

type Repeater

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

Repeater manages repeated functions.

func New

func New(clock clock.Clock) *Repeater

New creates a new Repeater with the specified clock.

func (*Repeater) Add

func (r *Repeater) Add(ctx context.Context, id int64, fn func(ctx context.Context, id int64) (readd bool), start time.Time, interval time.Duration) error

Add adds a repeated task occurring at an interval, given the specified ID.

func (*Repeater) AddCron

func (r *Repeater) AddCron(ctx context.Context, id int64, fn func(ctx context.Context, id int64) (readd bool), expr *Cron) error

AddCron adds a repeated task which repeats based on a cron expression. Cron tasks may safely share IDs with regular repeated tasks.

func (*Repeater) Count

func (r *Repeater) Count(ctx context.Context) (repeats, schedules int, err error)

Count returns the number of repeated and scheduled functions.

func (*Repeater) Remove

func (r *Repeater) Remove(ctx context.Context, id int64) error

Remove removes a repeated task.

func (*Repeater) RemoveCron

func (r *Repeater) RemoveCron(ctx context.Context, id int64) error

RemoveCron removes a repeated cron task.

func (*Repeater) Reset

func (r *Repeater) Reset(ctx context.Context) error

Reset resets a repeater, cancelling and removing all of its repeated functions.

func (*Repeater) Run

func (r *Repeater) Run(ctx context.Context) error

Run runs the repeater until the context is canceled.

Jump to

Keyboard shortcuts

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