pcron

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

定时任务,为了方便后续统一维护和二次扩展,故此将所有的方法重新二次封装一遍

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelayAdd

func DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAdd adds a timed task to default cron object after `delay` time.

func DelayAddOnce

func DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAddOnce adds a timed task after `delay` time to default cron object. This timed task can be run only once.

func DelayAddSingleton

func DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAddSingleton adds a singleton timed task after `delay` time to default cron object.

func DelayAddTimes

func DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, job JobFunc, name ...string)

DelayAddTimes adds a timed task after `delay` time to default cron object. This timed task can be run specified times.

func Remove

func Remove(name string)

Remove deletes scheduled task which named `name`.

func Size

func Size() int

Size returns the size of the timed tasks of default cron.

func Start

func Start(name ...string)

Start starts running the specified timed task named `name`. If no`name` specified, it starts the entire cron.

func Stop

func Stop(name ...string)

Stop stops running the specified timed task named `name`. If no`name` specified, it stops the entire cron.

Types

type Entry

type Entry = *gcron.Entry

func Add

func Add(ctx context.Context, pattern string, job JobFunc, name ...string) (Entry, error)

Add adds a timed task to default cron object. A unique `name` can be bound with the timed task. It returns and error if the `name` is already used.

func AddOnce

func AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (Entry, error)

AddOnce adds a timed task which can be run only once, to default cron object. A unique `name` can be bound with the timed task. It returns and error if the `name` is already used.

func AddSingleton

func AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (Entry, error)

AddSingleton adds a singleton timed task, to default cron object. A singleton timed task is that can only be running one single instance at the same time. A unique `name` can be bound with the timed task. It returns and error if the `name` is already used.

func AddTimes

func AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (Entry, error)

AddTimes adds a timed task which can be run specified times, to default cron object. A unique `name` can be bound with the timed task. It returns and error if the `name` is already used.

func Entries

func Entries() []Entry

Entries return all timed tasks as slice.

func Search(name string) Entry

Search returns a scheduled task with the specified `name`. It returns nil if no found.

type JobFunc

type JobFunc = gtimer.JobFunc

JobFunc is the timing called job function in timer.

Jump to

Keyboard shortcuts

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