mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: spin clock library out to coder/quartz repo (#13777)
Code that was in `/clock` has been moved to github.com/coder/quartz. This PR refactors our use of the clock library to point to the external Quartz repo.
This commit is contained in:
@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
// Notifier triggers callbacks at given intervals until some event happens. The
|
||||
@ -26,7 +26,7 @@ type Notifier struct {
|
||||
countdown []time.Duration
|
||||
|
||||
// for testing
|
||||
clock clock.Clock
|
||||
clock quartz.Clock
|
||||
}
|
||||
|
||||
// Condition is a function that gets executed periodically, and receives the
|
||||
@ -43,7 +43,7 @@ type Condition func(now time.Time) (deadline time.Time, callback func())
|
||||
type Option func(*Notifier)
|
||||
|
||||
// WithTestClock is used in tests to inject a mock Clock
|
||||
func WithTestClock(clk clock.Clock) Option {
|
||||
func WithTestClock(clk quartz.Clock) Option {
|
||||
return func(n *Notifier) {
|
||||
n.clock = clk
|
||||
}
|
||||
@ -67,7 +67,7 @@ func New(cond Condition, interval time.Duration, countdown []time.Duration, opts
|
||||
countdown: ct,
|
||||
condition: cond,
|
||||
notifiedAt: make(map[time.Duration]bool),
|
||||
clock: clock.NewReal(),
|
||||
clock: quartz.NewReal(),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(n)
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/coder/v2/coderd/autobuild/notify"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
func TestNotifier(t *testing.T) {
|
||||
@ -87,7 +87,7 @@ func TestNotifier(t *testing.T) {
|
||||
t.Run(testCase.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
mClock.Set(now).MustWait(ctx)
|
||||
numConditions := 0
|
||||
numCalls := 0
|
||||
|
@ -39,7 +39,6 @@ import (
|
||||
"cdr.dev/slog"
|
||||
agentproto "github.com/coder/coder/v2/agent/proto"
|
||||
"github.com/coder/coder/v2/buildinfo"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
_ "github.com/coder/coder/v2/coderd/apidoc" // Used for swagger docs.
|
||||
"github.com/coder/coder/v2/coderd/appearance"
|
||||
"github.com/coder/coder/v2/coderd/audit"
|
||||
@ -76,6 +75,7 @@ import (
|
||||
"github.com/coder/coder/v2/provisionersdk"
|
||||
"github.com/coder/coder/v2/site"
|
||||
"github.com/coder/coder/v2/tailnet"
|
||||
"github.com/coder/quartz"
|
||||
"github.com/coder/serpent"
|
||||
)
|
||||
|
||||
@ -573,7 +573,7 @@ func New(options *Options) *API {
|
||||
options.PrometheusRegistry.MustRegister(stn)
|
||||
}
|
||||
api.NetworkTelemetryBatcher = tailnet.NewNetworkTelemetryBatcher(
|
||||
clock.NewReal(),
|
||||
quartz.NewReal(),
|
||||
api.Options.NetworkTelemetryBatchFrequency,
|
||||
api.Options.NetworkTelemetryBatchMaxSize,
|
||||
api.handleNetworkTelemetry,
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -31,15 +31,15 @@ type Watchdog struct {
|
||||
timeout chan struct{}
|
||||
|
||||
// for testing
|
||||
clock clock.Clock
|
||||
clock quartz.Clock
|
||||
}
|
||||
|
||||
func NewWatchdog(ctx context.Context, logger slog.Logger, ps Pubsub) *Watchdog {
|
||||
return NewWatchdogWithClock(ctx, logger, ps, clock.NewReal())
|
||||
return NewWatchdogWithClock(ctx, logger, ps, quartz.NewReal())
|
||||
}
|
||||
|
||||
// NewWatchdogWithClock returns a watchdog with the given clock. Product code should always call NewWatchDog.
|
||||
func NewWatchdogWithClock(ctx context.Context, logger slog.Logger, ps Pubsub, c clock.Clock) *Watchdog {
|
||||
func NewWatchdogWithClock(ctx context.Context, logger slog.Logger, ps Pubsub, c quartz.Clock) *Watchdog {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
w := &Watchdog{
|
||||
ctx: ctx,
|
||||
|
@ -8,15 +8,15 @@ import (
|
||||
|
||||
"cdr.dev/slog"
|
||||
"cdr.dev/slog/sloggers/slogtest"
|
||||
"github.com/coder/coder/v2/clock"
|
||||
"github.com/coder/coder/v2/coderd/database/pubsub"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
"github.com/coder/quartz"
|
||||
)
|
||||
|
||||
func TestWatchdog_NoTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
|
||||
fPS := newFakePubsub()
|
||||
|
||||
@ -74,7 +74,7 @@ func TestWatchdog_NoTimeout(t *testing.T) {
|
||||
func TestWatchdog_Timeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
mClock := clock.NewMock(t)
|
||||
mClock := quartz.NewMock(t)
|
||||
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
|
||||
fPS := newFakePubsub()
|
||||
|
||||
|
Reference in New Issue
Block a user