Documentation
¶
Index ¶
- func ParseInterval(interval string) (time.Duration, error)
- func RunOnce(task func() error) error
- func RunOnceOrPeriodic(ctx context.Context, once bool, interval string, task func() error) error
- func SetupGracefulShutdown() (context.Context, context.CancelFunc)
- func StartPeriodicTask(ctx context.Context, interval string, task func() error) error
- func WaitForShutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseInterval ¶
ParseInterval parses a duration string and returns a time.Duration. Returns an error if the interval is invalid.
func RunOnce ¶
RunOnce executes the task function once immediately. Returns an error if the task fails.
func RunOnceOrPeriodic ¶ added in v1.1.0
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 ¶
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.