Documentation
¶
Overview ¶
Package pitayacron extends robfig/cron with optional etcd leader election for Pitaya services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultNodeID ¶
func DefaultNodeID() string
DefaultNodeID builds a readable process-unique identity for election and local execution metadata.
Types ¶
type Config ¶
type Config struct {
Namespace string
NodeID string
WithSeconds bool
Location string
Standalone bool
Election ElectionConfig
RetryInterval time.Duration
ShutdownTimeout time.Duration
}
Config controls cron parsing, election retry, and shutdown behavior.
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron runs ordinary jobs on every process and distributed jobs only on the current etcd leader. Cron implements Pitaya's interfaces.Module method set.
func New ¶
func New(config Config, dependencies Dependencies) (*Cron, error)
New creates a Cron using the built-in etcd election driver when an etcd dependency is supplied. The client remains owned by the caller.
func NewWithElector ¶
NewWithElector creates a Cron with a custom election driver. It is mainly useful for tests or non-etcd election implementations.
func (*Cron) AddDistributedJob ¶
AddDistributedJob registers a job that executes only on the current etcd leader. Every election participant must register the same distributed jobs.
func (*Cron) AddLocalJob ¶
AddLocalJob registers a job that executes independently on every process. Jobs must be registered before Init.
func (*Cron) BeforeShutdown ¶
func (c *Cron) BeforeShutdown()
BeforeShutdown cancels local handlers and the active election term.
type Dependencies ¶
Dependencies are caller-owned resources. Cron never closes the etcd client.
type ElectionConfig ¶
type ElectionConfig struct {
Prefix string
TTL int
ResignTimeout time.Duration
CallbackTimeout time.Duration
}
ElectionConfig controls the built-in etcd election driver.
type Elector ¶
type Elector interface {
Run(ctx context.Context, nodeID string, leader LeaderFunc) error
}
Elector serializes distributed cron execution across processes.
type Handler ¶
Handler executes a cron task. Distributed handlers should be idempotent and stop promptly when ctx is canceled after leadership loss.
type LeaderFunc ¶
LeaderFunc runs while the caller owns distributed leadership. Epoch is a monotonically increasing fencing token supplied by the election backend.