smegmesh/pkg/sync/syncscheduler.go

33 lines
790 B
Go
Raw Normal View History

2023-10-10 21:14:40 +02:00
package sync
import (
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
"github.com/tim-beatham/wgmesh/pkg/lib"
2023-10-10 21:14:40 +02:00
)
// SyncScheduler: Loops through all nodes in the mesh and runs a schedule to
// sync each event
type SyncScheduler interface {
Run() error
Stop() error
}
// SyncSchedulerImpl scheduler for sync scheduling
2023-10-10 21:14:40 +02:00
type SyncSchedulerImpl struct {
2023-11-03 16:24:18 +01:00
quit chan struct{}
server *ctrlserver.MeshCtrlServer
syncer Syncer
2023-10-10 21:14:40 +02:00
}
// Run implements SyncScheduler.
func syncFunction(syncer Syncer) lib.TimerFunc {
return func() error {
return syncer.SyncMeshes()
2023-10-10 21:14:40 +02:00
}
}
func NewSyncScheduler(s *ctrlserver.MeshCtrlServer, syncRequester SyncRequester) *lib.Timer {
2023-11-03 16:24:18 +01:00
syncer := NewSyncer(s.MeshManager, s.Conf, syncRequester)
return lib.NewTimer(syncFunction(syncer), int(s.Conf.SyncRate))
2023-10-10 21:14:40 +02:00
}