taskhelper

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package taskhelper provides struct and methods to help to synchronize different async.Task together and to simply start the async.Task properly This package should mainly used through the package app and not directly by the developer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinAll

func JoinAll(ctx context.Context, timeout time.Duration, helpers []Helper)

JoinAll is waiting for context to be canceled. A task that is ended and should stop the whole application, must have called the master cancelFunc shared by every TaskRunner which will closed the master context.

func Run

func Run(ctx context.Context, cancelFunc context.CancelFunc, t Helper)

Run is executing in a go-routing the Helper that handles a unique task

func WaitAll added in v0.28.0

func WaitAll(timeout time.Duration, helpers []Helper)

WaitAll is waiting for all the helpers to be done or for the timeout to be reached.

Types

type Helper

type Helper interface {
	fmt.Stringer
	Start(ctx context.Context, cancelFunc context.CancelFunc) error
	// Done returns the channel used to wait for the task job to be finalized
	Done() <-chan struct{}
}

Helper is an interface that defines a wrapper of the task that would help to execute it. Even if this interface is public, you usually don't have to implement it yourself, you just have to implement a Task or a SimpleTask

func New

func New(task any) (Helper, error)

func NewCron

func NewCron(task any, cronSchedule string) (Helper, error)

NewCron is returning a Helper that will execute the task according to the schedule. cronSchedule is following the standard syntax described here: https://en.wikipedia.org/wiki/Cron. It also supports the predefined scheduling definitions: - @yearly (or @annually) | Run once a year, midnight, Jan. 1st | 0 0 0 1 1 * - @monthly | Run once a month, midnight, first of month | 0 0 0 1 * * - @weekly | Run once a week, midnight between Sat/Sun | 0 0 0 * * 0 - @daily (or @midnight) | Run once a day, midnight | 0 0 0 * * * - @hourly | Run once an hour, beginning of hour | 0 0 * * * *

We are directly relying on what the library https://pkg.go.dev/github.com/robfig/cron is supporting.

func NewTick added in v0.23.0

func NewTick(task any, interval time.Duration) (Helper, error)

NewTick is returning a Helper that will execute the task periodically. The task can be a SimpleTask or a Task. It returns an error if it's something different

Jump to

Keyboard shortcuts

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