Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
30
cloud/maplepress-backend/pkg/leaderelection/provider.go
Normal file
30
cloud/maplepress-backend/pkg/leaderelection/provider.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package leaderelection
|
||||
|
||||
import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/config"
|
||||
)
|
||||
|
||||
// ProvideLeaderElection provides a LeaderElection instance for Wire DI.
|
||||
func ProvideLeaderElection(
|
||||
cfg *config.Config,
|
||||
redisClient *redis.Client,
|
||||
logger *zap.Logger,
|
||||
) (LeaderElection, error) {
|
||||
// Create configuration from app config
|
||||
// InstanceID and Hostname are auto-generated by NewRedisLeaderElection
|
||||
leConfig := &Config{
|
||||
RedisKeyName: "maplepress:leader:lock",
|
||||
RedisInfoKeyName: "maplepress:leader:info",
|
||||
LockTTL: cfg.LeaderElection.LockTTL,
|
||||
HeartbeatInterval: cfg.LeaderElection.HeartbeatInterval,
|
||||
RetryInterval: cfg.LeaderElection.RetryInterval,
|
||||
InstanceID: "", // Auto-generated from hostname + random suffix
|
||||
Hostname: "", // Auto-detected from os.Hostname()
|
||||
}
|
||||
|
||||
// redis.Client implements redis.UniversalClient interface
|
||||
return NewRedisLeaderElection(leConfig, redisClient, logger)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue