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/maplefile-backend/pkg/leaderelection/provider.go
Normal file
30
cloud/maplefile-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/maplefile-backend/config"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/pkg/distributedmutex"
|
||||
)
|
||||
|
||||
// ProvideLeaderElection provides a LeaderElection instance for Wire DI.
|
||||
func ProvideLeaderElection(
|
||||
cfg *config.Config,
|
||||
mutex distributedmutex.Adapter,
|
||||
redisClient redis.UniversalClient,
|
||||
logger *zap.Logger,
|
||||
) (LeaderElection, error) {
|
||||
// Create configuration from app config
|
||||
leConfig := &Config{
|
||||
RedisKeyName: "maplefile:leader:lock",
|
||||
RedisInfoKeyName: "maplefile:leader:info",
|
||||
LockTTL: cfg.LeaderElection.LockTTL,
|
||||
HeartbeatInterval: cfg.LeaderElection.HeartbeatInterval,
|
||||
RetryInterval: cfg.LeaderElection.RetryInterval,
|
||||
InstanceID: cfg.LeaderElection.InstanceID,
|
||||
Hostname: cfg.LeaderElection.Hostname,
|
||||
}
|
||||
|
||||
return NewMutexLeaderElection(leConfig, mutex, redisClient, logger)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue