ticker

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPrecision = time.Millisecond * 100

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

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

Scheduler is used to create and manage TaskConfig. Thread-safe.

Example:

s := NewScheduler(DefaultPrecision)
s.Every(1).Seconds().Do(func(t *Task) error { return nil })
s.Every(2).Hours().Do(func(t *Task) error { return nil })
s.Every().Day().Do(func(t *Task) error { return nil })
s.Start()

func NewScheduler

func NewScheduler(precision time.Duration) *Scheduler

NewScheduler creates a new scheduler.

Smaller precision may add to CPU load with many taskConfigs running, due to periodical checks.

func (*Scheduler) Every

func (s *Scheduler) Every(interval ...int) *TaskConfig

Every begins configuring a task. supply zero or one intervals. no intervals will be counted as 1

func (*Scheduler) Once

func (s *Scheduler) Once() *TaskConfig

Once begins configuring a task. sets the task to run only once. use TaskConfig.After or TaskConfig.From to set the time.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start starts the scheduler.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the scheduler.

type Task

type Task struct {
	Payload interface{}
	Elapsed time.Duration
	// contains filtered or unexported fields
}

Task is passed to task handlers and contains the payload

func (*Task) Id added in v0.0.15

func (t *Task) Id() uuid.UUID

Id returns the task id.

func (*Task) Stop

func (t *Task) Stop()

Stop stops the task.

type TaskConfig

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

func (*TaskConfig) After

func (tc *TaskConfig) After(interval time.Duration) *TaskConfig

After starts the task after the specified duration. Short hand for From(time.Now().Add(interval))

func (*TaskConfig) At

func (tc *TaskConfig) At(hour, minute int) *TaskConfig

At sets the time of day to run the task.

func (*TaskConfig) Day

func (tc *TaskConfig) Day() *TaskConfig

Day sets the interval to days.

func (*TaskConfig) Days

func (tc *TaskConfig) Days() *TaskConfig

Days is same as Day.

func (*TaskConfig) Do

func (tc *TaskConfig) Do(f TaskHandler, payload ...interface{}) *TaskConfig

Do start the task with the supplied payload in a new goroutine.

func (*TaskConfig) Friday

func (tc *TaskConfig) Friday() *TaskConfig

Friday sets the unit to weeks and only runs on Fridays.

func (*TaskConfig) From

func (tc *TaskConfig) From(from time.Time) *TaskConfig

From sets the start time of the task.

func (*TaskConfig) Hour

func (tc *TaskConfig) Hour() *TaskConfig

Hour sets the interval to hours.

func (*TaskConfig) Hours

func (tc *TaskConfig) Hours() *TaskConfig

Hours is same as Hour.

func (*TaskConfig) Millisecond added in v0.0.15

func (tc *TaskConfig) Millisecond() *TaskConfig

Millisecond sets the interval to milliseconds.

func (*TaskConfig) Milliseconds added in v0.0.15

func (tc *TaskConfig) Milliseconds() *TaskConfig

Milliseconds is same as Millisecond.

func (*TaskConfig) Minute

func (tc *TaskConfig) Minute() *TaskConfig

Minute sets the interval to minutes.

func (*TaskConfig) Minutes

func (tc *TaskConfig) Minutes() *TaskConfig

Minutes is same as Minute.

func (*TaskConfig) Monday

func (tc *TaskConfig) Monday() *TaskConfig

Monday sets the unit to weeks and only runs on Mondays.

func (*TaskConfig) OnBeforeStart added in v0.0.15

func (tc *TaskConfig) OnBeforeStart(f TaskHandler) *TaskConfig

OnBeforeStart sets the handler to be called before the task starts.

func (*TaskConfig) OnError added in v0.0.15

func (tc *TaskConfig) OnError(f TaskErrorHandler) *TaskConfig

OnError sets the error handler for the task. Errors happening in tasks won't stop the task from running. Call Task.Stop to stop the task.

func (*TaskConfig) OnFinish added in v0.0.15

func (tc *TaskConfig) OnFinish(f TaskHandler) *TaskConfig

OnFinish sets the finish handler for the task.

func (*TaskConfig) Saturday

func (tc *TaskConfig) Saturday() *TaskConfig

Saturday sets the unit to weeks and only runs on Saturdays.

func (*TaskConfig) Second

func (tc *TaskConfig) Second() *TaskConfig

Second sets the interval to seconds.

func (*TaskConfig) Seconds

func (tc *TaskConfig) Seconds() *TaskConfig

Seconds is same as Second.

func (*TaskConfig) Sunday

func (tc *TaskConfig) Sunday() *TaskConfig

Sunday sets the unit to weeks and only runs on Sundays.

func (*TaskConfig) Thursday

func (tc *TaskConfig) Thursday() *TaskConfig

Thursday sets the unit to weeks and only runs on Thursdays.

func (*TaskConfig) To

func (tc *TaskConfig) To(to time.Time) *TaskConfig

To sets the end time of the task.

func (*TaskConfig) Tuesday

func (tc *TaskConfig) Tuesday() *TaskConfig

Tuesday sets the unit to weeks and only runs on Tuesdays.

func (*TaskConfig) Wednesday

func (tc *TaskConfig) Wednesday() *TaskConfig

Wednesday sets the unit to weeks and only runs on Wednesdays.

func (*TaskConfig) Week

func (tc *TaskConfig) Week() *TaskConfig

Week sets the interval to weeks.

func (*TaskConfig) Weeks

func (tc *TaskConfig) Weeks() *TaskConfig

Weeks is same as Week.

type TaskErrorHandler added in v0.0.15

type TaskErrorHandler func(error, *Task)

type TaskHandler added in v0.0.15

type TaskHandler func(*Task) error

Jump to

Keyboard shortcuts

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