worker

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package worker 提供可组合到 beauty.App 的后台工作者 Service 实现。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLeaderTicker

func NewLeaderTicker(name string, elector dlock.Elector, interval time.Duration, fn func(ctx context.Context), opts ...TickerOption) *leaderTickerService

NewLeaderTicker 创建带选主的定时 Service。只有 leader 实例运行 fn。

elector, _ := dlock.NewElectorAuto()
beauty.New(
    worker.NewLeaderTicker("sync", elector, 10*time.Second, syncFn),
)

func NewTicker

func NewTicker(name string, interval time.Duration, fn func(ctx context.Context), opts ...TickerOption) *tickerService

NewTicker 创建定时执行 fn 的 Service。ctx 取消时停止。

beauty.New(
    worker.NewTicker("cleanup", 5*time.Minute, cleanupFn),
)

Types

type TickerOption

type TickerOption func(*tickerConfig)

TickerOption 配置 Ticker 行为。

func WithImmediate

func WithImmediate() TickerOption

WithImmediate 启动时立即执行一次 fn,不等第一个 interval。

Jump to

Keyboard shortcuts

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