Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Registry interface {
// NewGroup creates a new group of jobs which can be started and stopped together as part of the cells lifecycle.
// The provided scope is used to report health status of the jobs. A `cell.Scope` can be obtained via injection
// an object with the correct scope is provided by the closest `cell.Module`.
NewGroup(health cell.Health, opts ...groupOpt) Group
NewGroup(health cell.Health, opts ...GroupOpt) Group
}

type registry struct {
Expand All @@ -55,7 +55,7 @@ func newRegistry(

// NewGroup creates a new Group with the given `opts` options, which allows you to customize the behavior for the
// group as a whole. For example by allowing you to add pprof labels to the group or by customizing the logger.
func (c *registry) NewGroup(health cell.Health, opts ...groupOpt) Group {
func (c *registry) NewGroup(health cell.Health, opts ...GroupOpt) Group {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -120,25 +120,25 @@ type options struct {
metrics Metrics
}

type groupOpt func(o *options)
type GroupOpt func(o *options)

// WithLogger replaces the default logger with the given logger, useful if you want to add certain fields to the logs
// created by the group/jobs.
func WithLogger(logger *slog.Logger) groupOpt {
func WithLogger(logger *slog.Logger) GroupOpt {
return func(o *options) {
o.logger = logger
}
}

// WithPprofLabels adds pprof labels which will be added to the goroutines spawned for the jobs and thus included in
// the pprof profiles.
func WithPprofLabels(pprofLabels pprof.LabelSet) groupOpt {
func WithPprofLabels(pprofLabels pprof.LabelSet) GroupOpt {
return func(o *options) {
o.pprofLabels = pprofLabels
}
}

func WithMetrics(metrics Metrics) groupOpt {
func WithMetrics(metrics Metrics) GroupOpt {
return func(o *options) {
o.metrics = metrics
}
Expand Down
10 changes: 5 additions & 5 deletions job/oneshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
//
// The given function is expected to exit as soon as the context given to it expires, this is especially important for
// blocking or long running jobs.
func OneShot(name string, fn OneShotFunc, opts ...jobOneShotOpt) Job {
func OneShot(name string, fn OneShotFunc, opts ...JobOneShotOpt) Job {
if fn == nil {
panic("`fn` must not be nil")
}
Expand All @@ -35,7 +35,7 @@ func OneShot(name string, fn OneShotFunc, opts ...jobOneShotOpt) Job {
return job
}

type jobOneShotOpt func(*jobOneShot)
type JobOneShotOpt func(*jobOneShot)

type RetryBackoff interface {
Wait() time.Duration
Expand Down Expand Up @@ -68,7 +68,7 @@ func (e *ExponentialBackoff) Wait() time.Duration {
// WithRetry option configures a one shot job to retry `times` amount of times. On each retry attempt the
// rate limiter is waited upon before making another attempt.
// If `times` is <0, then the job is retried forever.
func WithRetry(times int, backoff RetryBackoff) jobOneShotOpt {
func WithRetry(times int, backoff RetryBackoff) JobOneShotOpt {
return func(jos *jobOneShot) {
jos.retry = times
jos.backoff = backoff
Expand All @@ -77,7 +77,7 @@ func WithRetry(times int, backoff RetryBackoff) jobOneShotOpt {

// WithShutdown option configures a one shot job to shutdown the whole hive if the job returns an error. If the
// WithRetry option is also configured, all retries must be exhausted before we trigger the shutdown.
func WithShutdown() jobOneShotOpt {
func WithShutdown() JobOneShotOpt {
return func(jos *jobOneShot) {
jos.shutdownOnError = true
}
Expand All @@ -90,7 +90,7 @@ type OneShotFunc func(ctx context.Context, health cell.Health) error
type jobOneShot struct {
name string
fn OneShotFunc
opts []jobOneShotOpt
opts []JobOneShotOpt

health cell.Health

Expand Down
14 changes: 7 additions & 7 deletions job/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// interval, its next invocation is not delayed. The `fn` is expected to stop as soon as the context passed to it
// expires. This is especially important for long running functions. The signal created by a Trigger is coalesced so
// multiple calls to trigger before the invocation takes place can result in just a single invocation.
func Timer(name string, fn TimerFunc, interval time.Duration, opts ...timerOpt) Job {
func Timer(name string, fn TimerFunc, interval time.Duration, opts ...TimerOpt) Job {
if fn == nil {
panic("`fn` must not be nil")
}
Expand All @@ -42,7 +42,7 @@ func Timer(name string, fn TimerFunc, interval time.Duration, opts ...timerOpt)
// TimerFunc is the func type invoked by a timer job. A TimerFunc is expected to return as soon as the ctx expires.
type TimerFunc func(ctx context.Context) error

type timerOpt func(*jobTimer)
type TimerOpt func(*jobTimer)

// Trigger which can be used to trigger a timer job, trigger events are coalesced.
type Trigger interface {
Expand All @@ -51,7 +51,7 @@ type Trigger interface {
}

// NewTrigger creates a new trigger, which can be used to trigger a timer job.
func NewTrigger(opts ...triggerOpt) *trigger {
func NewTrigger(opts ...TriggerOpt) *trigger {
t := &trigger{
c: make(chan struct{}, 1),
}
Expand All @@ -62,7 +62,7 @@ func NewTrigger(opts ...triggerOpt) *trigger {
}

// WithDebounce allows to specify an interval over with multiple trigger requests will be folded into one.
func WithDebounce(interval time.Duration) triggerOpt {
func WithDebounce(interval time.Duration) TriggerOpt {
return func(t *trigger) {
t.debounce = interval
}
Expand Down Expand Up @@ -118,11 +118,11 @@ func (t *trigger) markTriggered(name string, metrics Metrics) {
}
}

type triggerOpt func(t *trigger)
type TriggerOpt func(t *trigger)

// WithTrigger option allows a user to specify a trigger, which if triggered will invoke the function of a timer
// before the configured interval has expired.
func WithTrigger(trig Trigger) timerOpt {
func WithTrigger(trig Trigger) TimerOpt {
return func(jt *jobTimer) {
jt.trigger = trig.(*trigger)
}
Expand All @@ -131,7 +131,7 @@ func WithTrigger(trig Trigger) timerOpt {
type jobTimer struct {
name string
fn TimerFunc
opts []timerOpt
opts []TimerOpt

health cell.Health

Expand Down
Loading