executor

package
v0.2.15 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	Start(ctx context.Context, params any) error
	Stop(wait bool) error
	Stats() *Stats
}

func New

func New(j job.Job, opts ...Option) Executor

type Option

type Option func(*executor)

func NoTimeout

func NoTimeout() Option

func Once

func Once() Option

Once configures the executor to allow only a single successful Start() call. After the first successful execution, subsequent Start() calls will return an error.

Note: Once() is compatible with WithRetry(). When both are used:

  • The first Start() call can retry on failure (if WithRetry is configured)
  • Only one successful Start() execution is allowed
  • Once a Start() call succeeds, no further Start() calls are permitted

This is useful for idempotent initialization tasks that should only complete once but may need retries due to transient failures.

Example:

je := New(job, Once(), WithRetry(3, 1*time.Second))
je.Start(...) // May retry up to 3 times on failure
je.Start(...) // Returns error if previous call succeeded

func WithCooldown

func WithCooldown(cooldown time.Duration) Option

func WithRetry

func WithRetry(attempts int, interval time.Duration) Option

WithRetry configures the executor to retry failed job executions. The retry mechanism applies to each Start() call independently.

Parameters:

  • attempts: number of retry attempts (must be > 0)
  • interval: delay between retry attempts

Note: WithRetry is compatible with Once(). When both are used:

  • Once() restricts the number of successful Start() calls to one
  • WithRetry() allows retries within that single Start() call

Example:

je := New(job, Once(), WithRetry(3, 1*time.Second))
je.Start(...) // Will retry up to 3 times on failure
je.Start(...) // Will return error "job can only start once" if first call succeeded

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type Stats

type Stats struct {
	Retries  uint          `json:"retries"`
	Cooldown time.Duration `json:"cooldown"`
}

Jump to

Keyboard shortcuts

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