func NewServiceWith(leaseClient client.LeaseClient, ticker util.Ticker, currentTimeFn func() time.Time) *Service {
	service := &Service{
		state:               &sync.Map{},
		leaseClient:         leaseClient,
		syncTicker:          ticker,
		currentTimeProvider: currentTimeFn,
		doneChannel:         make(chan bool),
	}
	service.doneWG.Add(1)
	go service.haStateSyncer()
	return service
}
NewServiceWith constructs a new HA lease service with the leaseClient,
ticker and a current time provide function.
The ticker determines when the lease states for all clusters
are refreshed from the database, the currentTimeFn determines the
current time, used for deterministic tests.
package ha
import (
	"context"
	"fmt"
	"sync"
	"time"
	"github.com/timescale/promscale/pkg/ha/client"
	"github.com/timescale/promscale/pkg/ha/state"
	"github.com/timescale/promscale/pkg/log"
	"github.com/timescale/promscale/pkg/util"
)
const (
	haSyncerTimeInterval      = 15 * time.Second
	tryLeaderChangeErrFmt     = "failed to attempt leader change for cluster %s"
	failedToUpdateLeaseErrFmt = "failed to update lease for cluster %s"
)
var ErrNoLeasesInRange = fmt.Errorf("no valid leases in range found")
type Service struct {
	state               *sync.Map
	leaseClient         client.LeaseClient
	syncTicker          util.Ticker
	currentTimeProvider func() time.Time
	doneChannel         chan bool
	doneWG              sync.WaitGroup
}
func NewService(leaseClient client.LeaseClient) *Service {
	return NewServiceWith(leaseClient, util.NewTicker(haSyncerTimeInterval), time.Now)
}