common

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseInterval

func ParseInterval(interval string) (time.Duration, error)

ParseInterval parses a duration string and returns a time.Duration. Returns an error if the interval is invalid.

func RunOnce

func RunOnce(task func() error) error

RunOnce executes the task function once immediately. Returns an error if the task fails.

func RunOnceOrPeriodic added in v1.1.0

func RunOnceOrPeriodic(ctx context.Context, once bool, interval string, task func() error) error

RunOnceOrPeriodic executes the task either once or periodically based on the once flag. If once is true, runs the task immediately and returns. If once is false, runs the task periodically at the specified interval.

func SetupGracefulShutdown

func SetupGracefulShutdown() (context.Context, context.CancelFunc)

SetupGracefulShutdown creates a context that will be cancelled on SIGINT or SIGTERM. Returns the context and a cleanup function that should be deferred. This provides consistent signal handling across all tools.

func StartPeriodicTask

func StartPeriodicTask(ctx context.Context, interval string, task func() error) error

StartPeriodicTask executes the given task function periodically at the specified interval. The task runs in a goroutine on each tick. The function blocks until the context is cancelled. If the context is cancelled, the ticker is stopped and the function returns nil.

func WaitForShutdown

func WaitForShutdown()

WaitForShutdown blocks until SIGINT or SIGTERM is received. Use this in serve commands that don't need a cancellable context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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