task

package
v0.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(*Task) error

type RunnerContainer

type RunnerContainer struct {
	Configs   []*TaskConfig
	Callbacks []Handler
	Runners   []*TaskRunner
}

func NewRunnerContainer

func NewRunnerContainer() *RunnerContainer

func (*RunnerContainer) Append

func (r *RunnerContainer) Append(cfg *TaskConfig, cb Handler)

func (*RunnerContainer) CloseAll

func (r *RunnerContainer) CloseAll() error

func (*RunnerContainer) StartAll

func (r *RunnerContainer) StartAll() error

func (*RunnerContainer) StartAllContext

func (r *RunnerContainer) StartAllContext(ctx context.Context) error

type Task

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

Task is passed to task handlers and contains the payload

func (*Task) Args

func (t *Task) Args() []any

Args returns the task arguments.

func (*Task) Elapsed

func (t *Task) Elapsed() time.Duration

Elapsed returns the time elapsed since the last run.

func (*Task) Id

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

Id returns the task id.

func (*Task) Name

func (t *Task) Name() string

func (*Task) Stop

func (t *Task) Stop()

Stop stops the task.

type TaskConfig

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

TaskConfig is responsible for configuring a task and scheduling it.

func Every

func Every(interval ...int) *TaskConfig

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

func Once

func Once() *TaskConfig

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

func (*TaskConfig) After

func (c *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 (c *TaskConfig) At(hour, minute int) *TaskConfig

At sets the time of day to run the task.

func (*TaskConfig) Clone

func (c *TaskConfig) Clone() *TaskConfig

Clone

func (*TaskConfig) Day

func (c *TaskConfig) Day() *TaskConfig

Day sets the interval to days.

func (*TaskConfig) Days

func (c *TaskConfig) Days() *TaskConfig

Days is same as Day.

func (*TaskConfig) Do

func (c *TaskConfig) Do(f Handler, args ...any) (r *TaskRunner, err error)

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

func (*TaskConfig) DoContext

func (c *TaskConfig) DoContext(ctx context.Context, f Handler, args ...any) (r *TaskRunner, err error)

DoContext run the task with the supplied payload in a new goroutine.

func (*TaskConfig) Friday

func (c *TaskConfig) Friday() *TaskConfig

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

func (*TaskConfig) From

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

From sets the run time of the task.

func (*TaskConfig) Hour

func (c *TaskConfig) Hour() *TaskConfig

Hour sets the interval to hours.

func (*TaskConfig) Hours

func (c *TaskConfig) Hours() *TaskConfig

Hours is same as Hour.

func (*TaskConfig) Millisecond

func (c *TaskConfig) Millisecond() *TaskConfig

Millisecond sets the interval to milliseconds.

func (*TaskConfig) Milliseconds

func (c *TaskConfig) Milliseconds() *TaskConfig

Milliseconds is same as Millisecond.

func (*TaskConfig) Minute

func (c *TaskConfig) Minute() *TaskConfig

Minute sets the interval to minutes.

func (*TaskConfig) Minutes

func (c *TaskConfig) Minutes() *TaskConfig

Minutes is same as Minute.

func (*TaskConfig) Monday

func (c *TaskConfig) Monday() *TaskConfig

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

func (*TaskConfig) OnBeforeStart

func (c *TaskConfig) OnBeforeStart(f Handler) *TaskConfig

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

func (*TaskConfig) OnFinish

func (c *TaskConfig) OnFinish(f Handler) *TaskConfig

OnFinish sets the finish handler for the task.

func (*TaskConfig) Saturday

func (c *TaskConfig) Saturday() *TaskConfig

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

func (*TaskConfig) Second

func (c *TaskConfig) Second() *TaskConfig

Second sets the interval to seconds.

func (*TaskConfig) Seconds

func (c *TaskConfig) Seconds() *TaskConfig

Seconds is same as Second.

func (*TaskConfig) Sunday

func (c *TaskConfig) Sunday() *TaskConfig

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

func (*TaskConfig) Thursday

func (c *TaskConfig) Thursday() *TaskConfig

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

func (*TaskConfig) To

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

To sets the end time of the task.

func (*TaskConfig) Tuesday

func (c *TaskConfig) Tuesday() *TaskConfig

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

func (*TaskConfig) Wednesday

func (c *TaskConfig) Wednesday() *TaskConfig

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

func (*TaskConfig) Week

func (c *TaskConfig) Week() *TaskConfig

Week sets the interval to weeks.

func (*TaskConfig) Weeks

func (c *TaskConfig) Weeks() *TaskConfig

Weeks is same as Week.

func (*TaskConfig) WithName

func (c *TaskConfig) WithName(name string) *TaskConfig

type TaskRunner

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

TaskRunner is responsible for running the task given to them

func (*TaskRunner) Close

func (r *TaskRunner) Close() error

Close closes the task runner.

Jump to

Keyboard shortcuts

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