storj/satellite/metabase/rangedloop/rangedlooptest/sleepobserver.go
Michal Niewrzal 4bdbb25d83 satellite/metabase/rangedloop: move Segment definition
We will remove segments loop soon so we need first to move
Segment definition to rangedloop package.

https://github.com/storj/storj/issues/5237

Change-Id: Ibe6aad316ffb7073cc4de166f1f17b87aac07363
2023-05-16 12:37:17 +00:00

45 lines
1.1 KiB
Go

// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package rangedlooptest
import (
"context"
"time"
"storj.io/storj/satellite/metabase/rangedloop"
)
// SleepObserver is a subscriber to the segment loop which sleeps for every batch.
type SleepObserver struct {
Duration time.Duration
}
// Start is the callback for segment loop start.
func (c *SleepObserver) Start(ctx context.Context, time time.Time) error {
return nil
}
// Fork splits the observer to process a segment range.
func (c *SleepObserver) Fork(ctx context.Context) (rangedloop.Partial, error) {
return c, nil
}
// Join is a noop.
func (c *SleepObserver) Join(ctx context.Context, partial rangedloop.Partial) error {
// Range done
return nil
}
// Finish is the callback for segment loop end.
func (c *SleepObserver) Finish(ctx context.Context) error {
return nil
}
// Process sleeps for every batch of segments to simulate execution time.
func (c *SleepObserver) Process(ctx context.Context, segments []rangedloop.Segment) error {
sleepTime := time.Duration(c.Duration.Nanoseconds() * int64(len(segments)))
time.Sleep(sleepTime)
return nil
}