Repository navigation
Use TimeProvider in RedisFacade and build net48 on all platforms - #739
Conversation
Remove the macOS/Linux-only condition that limited Halibut.csproj to net10.0. The SDK fetches the .NET Framework reference assemblies from NuGet, so net48 builds without Windows or Mono. Building net48 found two problems from adding Microsoft.Bcl.TimeProvider: - TimeProvider 11.0.0 needs Microsoft.Bcl.AsyncInterfaces >= 11.0.0 on net48, but we pinned 7.0.0, so restore failed with NU1605. Bump AsyncInterfaces to 11.0.0. - The Task.Delay(TimeSpan, TimeProvider, CancellationToken) overload only exists on net8+. Use the timeProvider.Delay(...) extension method, which the package provides for both net48 and net10.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0d73d3a to
056e55d
Compare
| if (!willRetry) throw; | ||
| log?.Write(EventType.Diagnostic, $"Redis operation failed, retrying in {retryDelay.TotalSeconds}s: {ex.Message}"); | ||
| await Task.Delay(retryDelay, combinedToken); | ||
| await timeProvider.Delay(retryDelay, combinedToken); |
There was a problem hiding this comment.
Note: If we only targeted net8 or net10, then the idiomatic way to do this is await Task.Delay(retryDelay, timeProvider, combinedToken). That's what we'd do in server.
However because we need to target net48, the Task.Delay overload which accepts a TimeProvider doesn't exist. Microsoft has an extension method for back compat, which we're using here instead.
FWIW the extension method is defined here: https://github.com/dotnet/runtime/blob/fea407997bf391030846ba0180b6c039f3b8c318/src/libraries/Microsoft.Bcl.TimeProvider/src/System/Threading/Tasks/TimeProviderTaskExtensions.cs#L49
You can see it takes a different path on net4x
There was a problem hiding this comment.
Redis Halibut queue doesn't work under net48, we have the option to make it not work under net48. Or remove the RedisFacade entirely from net48
🤖 Claude: (reviewed by 👨 Orion; I didn't see the need to change anything, claude has done well here)
Summary
RedisFacadenow takes aTimeProvider, so tests can control time in its retry logic.This PR also lets
Halibut.csprojbuild for net48 on macOS and Linux. That exposed two net48 problems with the new TimeProvider dependency, which are fixed here.Changes
Use
TimeProviderinRedisFacadeMicrosoft.Bcl.TimeProviderpackage reference.TimeProvideris built into net8+, and this package provides it for net48.RedisFacadeconstructors now require aTimeProvider. This breaks the public API: callers must pass one, usuallyTimeProvider.System.ExecuteWithRetryloops now usetimeProvider.GetTimestamp()/GetElapsedTime()instead ofStopwatch, andtimeProvider.Delay(...)instead ofTask.Delay(...).SubscribeToChannel's retry delay goes through a newDelayWithoutException.Delay(TimeSpan, TimeProvider, CancellationToken)overload.RedisFacadeBuilderaccepts an optionalTimeProvider, defaulting toTimeProvider.System. A comment inRedisFacadeFixtureexplains that these integration tests run against a live Redis and should use the real clock.Build net48 on every OS
Halibut.csprojno longer limits itself tonet10.0on macOS and Linux. It always targetsnet48;net10.0. The .NET SDK fetchesMicrosoft.NETFramework.ReferenceAssembliesfrom NuGet, so net48 compiles without Windows or Mono. Running net48 tests still needs Windows.net10.0off Windows.Fix net48 problems
Microsoft.Bcl.TimeProvider11.0.0 needsMicrosoft.Bcl.AsyncInterfaces11.0.0 or later, but we pinned 7.0.0.Microsoft.Bcl.AsyncInterfacesis bumped to 11.0.0, the latest stable version. Anything that uses the Halibut package now needs AsyncInterfaces 11.0.0 or later.Task.Delay(TimeSpan, TimeProvider, CancellationToken)only exists on net8+. The code calls thetimeProvider.Delay(delay, token)extension method instead. The package provides it for both net48 and net10.0, so no#ifis needed.Testing
dotnet build source/Halibut/Halibut.csprojsucceeds on macOS for bothnet48andnet10.0, with no warnings or errors.dotnet build source/Halibut.Tests/Halibut.Tests.csprojsucceeds fornet10.0.🤖 Generated with Claude Code