From f69ec3d33b4f33831acbc0984abceb258acd123d Mon Sep 17 00:00:00 2001 From: PJ Date: Wed, 31 Jul 2024 12:01:20 +0200 Subject: [PATCH] scanner: rename interface --- autopilot/scanner/scanner.go | 14 +++++++------- autopilot/scanner/scanner_test.go | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/autopilot/scanner/scanner.go b/autopilot/scanner/scanner.go index 15e82a035..e22730e1c 100644 --- a/autopilot/scanner/scanner.go +++ b/autopilot/scanner/scanner.go @@ -18,21 +18,21 @@ const ( ) type ( - HostScanner interface { - RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, timeout time.Duration) (api.RHPScanResponse, error) - } - HostStore interface { HostsForScanning(ctx context.Context, opts api.HostsForScanningOptions) ([]api.HostAddress, error) RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error) } Scanner interface { - Scan(ctx context.Context, w HostScanner, force bool) + Scan(ctx context.Context, w WorkerRHPScan, force bool) Shutdown(ctx context.Context) error Status() (bool, time.Time) UpdateHostsConfig(cfg api.HostsConfig) } + + WorkerRHPScan interface { + RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, timeout time.Duration) (api.RHPScanResponse, error) + } ) type ( @@ -87,7 +87,7 @@ func New(hs HostStore, scanBatchSize, scanThreads uint64, scanMinInterval time.D }, nil } -func (s *scanner) Scan(ctx context.Context, w HostScanner, force bool) { +func (s *scanner) Scan(ctx context.Context, w WorkerRHPScan, force bool) { if s.canSkipScan(force) { s.logger.Debug("host scan skipped") return @@ -194,7 +194,7 @@ func (s *scanner) fetchHosts(ctx context.Context, cutoff time.Time) chan scanJob return jobsChan } -func (s *scanner) scanHosts(ctx context.Context, w HostScanner, hosts chan scanJob) (scanned uint64) { +func (s *scanner) scanHosts(ctx context.Context, w WorkerRHPScan, hosts chan scanJob) (scanned uint64) { // define worker worker := func() { for h := range hosts { diff --git a/autopilot/scanner/scanner_test.go b/autopilot/scanner/scanner_test.go index c9997162f..537d878c0 100644 --- a/autopilot/scanner/scanner_test.go +++ b/autopilot/scanner/scanner_test.go @@ -64,14 +64,14 @@ func (hs *mockHostStore) state() ([]string, []string) { return hs.scans, hs.removals } -type mockHostScanner struct { +type mockWorker struct { blockChan chan struct{} mu sync.Mutex scanCount int } -func (w *mockHostScanner) RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, _ time.Duration) (api.RHPScanResponse, error) { +func (w *mockWorker) RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, _ time.Duration) (api.RHPScanResponse, error) { if w.blockChan != nil { <-w.blockChan } @@ -101,7 +101,7 @@ func TestScanner(t *testing.T) { } // initiate a host scan using a worker that blocks - w := &mockHostScanner{blockChan: make(chan struct{})} + w := &mockWorker{blockChan: make(chan struct{})} s.Scan(context.Background(), w, false) // assert it's scanning