core

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const PrefixV1 = "/conch/v1"

Variables

This section is empty.

Functions

func CronFireKey

func CronFireKey(name string, tickUnix int64) string

CronFireKey is the fire key for a job's specific tick

func CronFirePrefix

func CronFirePrefix(name string) string

CronFirePrefix is the prefix for all tick fire keys of a job

func CronJobKey

func CronJobKey(name string) string

CronJobKey is the spec key for a cron job

func CronJobPrefix

func CronJobPrefix() string

CronJobPrefix is the prefix for all cron jobs

func CronResultKey

func CronResultKey(name string, tickUnix int64) string

CronResultKey is the result key for a job's specific tick

func CronResultPrefix

func CronResultPrefix(name string) string

CronResultPrefix is the prefix for all results of a job

func ElectElectionKey

func ElectElectionKey(office string) string

ElectElectionKey is passed to concurrency.NewElection (without trailing slash)

func ElectPrefix

func ElectPrefix(office string) string

ElectPrefix is used to watch or fetch candidates for an office

func NewHolderJSON

func NewHolderJSON(cmdArgs []string) ([]byte, error)

func SemaKey

func SemaKey(name string, max int, spread bool, host string, leaseID int64) string

SemaKey is the leased key for a specific holder

func SemaPrefix

func SemaPrefix(name string, max int) string

SemaPrefix is the prefix for a semaphore name and capacity

Types

type Backoff

type Backoff struct {
	Base time.Duration
	Cap  time.Duration
	// contains filtered or unexported fields
}

func NewBackoff

func NewBackoff(base, cap time.Duration) *Backoff

func (*Backoff) Duration

func (b *Backoff) Duration() time.Duration

func (*Backoff) Reset

func (b *Backoff) Reset()

type CoreSession

type CoreSession struct {
	Client  *clientv3.Client
	Session *concurrency.Session
	LeaseID clientv3.LeaseID
	DoneCh  <-chan struct{}
}

func NewCoreSession

func NewCoreSession(ctx context.Context, endpoints []string, dialTimeout time.Duration, ttl time.Duration, logger *slog.Logger) (*CoreSession, error)

func (*CoreSession) Close

func (cs *CoreSession) Close()

type Holder

type Holder interface {
	Acquire(ctx context.Context) (int64, error)
	Release(ctx context.Context) error
	Name() string
	Key() string
}

type HolderJSON

type HolderJSON struct {
	Host    string `json:"host"`
	Pid     int    `json:"pid"`
	Started string `json:"started"`
	Cmd     string `json:"cmd,omitempty"`
}

type Outcome

type Outcome string
const (
	OutcomeExitNormal       Outcome = "exit-normal"
	OutcomeHoldLost         Outcome = "hold-lost"
	OutcomeSignalReceived   Outcome = "signal-received"
	OutcomeContextCancelled Outcome = "context-cancelled"
	OutcomeAcquireFailed    Outcome = "acquire-failed"
)

func Run

func Run(ctx context.Context, logger *slog.Logger, sess *CoreSession, hold Holder, cmdArgs []string, killAfter time.Duration) (int, Outcome, error)

func RunWithConfig

func RunWithConfig(ctx context.Context, logger *slog.Logger, sess *CoreSession, hold Holder, cmdArgs []string, killAfter time.Duration, cfg RunConfig) (int, Outcome, error)

type RunConfig

type RunConfig struct {
	OnAcquire   string
	OnLose      string
	HookTimeout time.Duration
}

Jump to

Keyboard shortcuts

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