Varakh
5763d77045
All checks were successful
/ build (push) Successful in 3m37s
- Disable cleaning up stale updates and events by default - Change Prometheus exporter behavior - Return -1 for deleted updates in Prometheus which are evicted on next application restart - Ignore PROMETHEUS_METRICS_PATH (defaults to /metrics) in application metrics - Improve template Grafana Dashboard - Add locking for background task in non-distributed environments to avoid overlaps
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"git.myservermanager.com/varakh/upda/util"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type lockMemService struct {
|
|
registry *util.InMemoryLockRegistry
|
|
}
|
|
|
|
func newLockMemService() lockService {
|
|
return &lockMemService{registry: util.NewInMemoryLockRegistry()}
|
|
}
|
|
|
|
func (s *lockMemService) init() error {
|
|
zap.L().Info("Initialized in-memory locking service")
|
|
return nil
|
|
}
|
|
|
|
func (s *lockMemService) tryLock(resource string) error {
|
|
if resource == "" {
|
|
return errorValidationNotBlank
|
|
}
|
|
|
|
zap.L().Sugar().Debugf("Trying to lock '%s'", resource)
|
|
s.registry.Lock(resource)
|
|
zap.L().Sugar().Debugf("Locked '%s'", resource)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *lockMemService) release(resource string) error {
|
|
if resource == "" {
|
|
return errorValidationNotBlank
|
|
}
|
|
|
|
zap.L().Sugar().Debugf("Releasing lock '%s'", resource)
|
|
err := s.registry.Unlock(resource)
|
|
zap.L().Sugar().Debugf("Released lock '%s'", resource)
|
|
|
|
return err
|
|
}
|
|
|
|
func (s *lockMemService) exists(resource string) bool {
|
|
return s.registry.Exists(resource)
|
|
}
|
|
|
|
func (s *lockMemService) stop() {
|
|
zap.L().Info("Clearing in-memory locking service")
|
|
s.registry.Clear()
|
|
}
|