Skip to content

Commit

Permalink
Merge pull request #34 from FoundatioFx/systemclock
Browse files Browse the repository at this point in the history
Adapt to SystemClock removal
  • Loading branch information
ejsmith authored Aug 31, 2024
2 parents 7817524 + 0c4c75a commit d2405c9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Foundatio.AzureStorage/Foundatio.AzureStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.3" />
<PackageReference Include="Microsoft.Azure.Storage.Queue" Version="11.2.3" />

<PackageReference Include="Foundatio" Version="10.7.1" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<PackageReference Include="Foundatio" Version="11.0.0" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<ProjectReference Include="..\..\..\Foundatio\src\Foundatio\Foundatio.csproj" Condition="'$(ReferenceFoundatioSource)' == 'true'" />
</ItemGroup>
</Project>
5 changes: 2 additions & 3 deletions src/Foundatio.AzureStorage/Queues/AzureStorageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Foundatio.AsyncEx;
using Foundatio.Extensions;
using Foundatio.Serializer;
using Foundatio.Utility;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Queue;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -74,7 +73,7 @@ protected override async Task<string> EnqueueImplAsync(T data, QueueEntryOptions
var message = new CloudQueueMessage(_serializer.SerializeToBytes(data));
await _queueReference.AddMessageAsync(message, null, options.DeliveryDelay, null, null).AnyContext();

var entry = new QueueEntry<T>(message.Id, null, data, this, SystemClock.UtcNow, 0);
var entry = new QueueEntry<T>(message.Id, null, data, this, _timeProvider.GetLocalNow().UtcDateTime, 0);
await OnEnqueuedAsync(entry).AnyContext();

return message.Id;
Expand All @@ -99,7 +98,7 @@ protected override async Task<IQueueEntry<T>> DequeueImplAsync(CancellationToken
try
{
if (!linkedCancellationToken.IsCancellationRequested)
await SystemClock.SleepAsync(_options.DequeueInterval, linkedCancellationToken).AnyContext();
await _timeProvider.Delay(_options.DequeueInterval, linkedCancellationToken).AnyContext();
}
catch (OperationCanceledException) { }

Expand Down
7 changes: 4 additions & 3 deletions src/Foundatio.AzureStorage/Storage/AzureFileStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -8,7 +8,6 @@
using Foundatio.Azure.Extensions;
using Foundatio.Extensions;
using Foundatio.Serializer;
using Foundatio.Utility;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Extensions.Logging;
Expand All @@ -21,12 +20,14 @@ public class AzureFileStorage : IFileStorage
private readonly CloudBlobContainer _container;
private readonly ISerializer _serializer;
protected readonly ILogger _logger;
protected readonly TimeProvider _timeProvider;

public AzureFileStorage(AzureFileStorageOptions options)
{
if (options == null)
throw new ArgumentNullException(nameof(options));

_timeProvider = options.TimeProvider ?? TimeProvider.System;
_serializer = options.Serializer ?? DefaultSerializer.Instance;
_logger = options.LoggerFactory?.CreateLogger(GetType()) ?? NullLogger.Instance;

Expand Down Expand Up @@ -170,7 +171,7 @@ public async Task<bool> CopyFileAsync(string path, string targetPath, Cancellati

await newBlob.StartCopyAsync(oldBlob, cancellationToken).AnyContext();
while (newBlob.CopyState.Status == CopyStatus.Pending)
await SystemClock.SleepAsync(50, cancellationToken).AnyContext();
await _timeProvider.Delay(TimeSpan.FromMilliseconds(50), cancellationToken).AnyContext();

return newBlob.CopyState.Status == CopyStatus.Success;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<NoWarn>$(NoWarn);CS1591;NU1701</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />

<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="All" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="All" />

<PackageReference Include="Foundatio.TestHarness" Version="10.7.1" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<PackageReference Include="Foundatio.TestHarness" Version="11.0.0" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<ProjectReference Include="..\..\..\Foundatio\src\Foundatio.TestHarness\Foundatio.TestHarness.csproj" Condition="'$(ReferenceFoundatioSource)' == 'true'" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\docker-compose.yml">
<Link>docker-compose.yml</Link>
</Content>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AzureStorageQueueTests : QueueTestBase

public AzureStorageQueueTests(ITestOutputHelper output) : base(output) { }

protected override IQueue<SimpleWorkItem> GetQueue(int retries = 1, TimeSpan? workItemTimeout = null, TimeSpan? retryDelay = null, int[] retryMultipliers = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true)
protected override IQueue<SimpleWorkItem> GetQueue(int retries = 1, TimeSpan? workItemTimeout = null, TimeSpan? retryDelay = null, int[] retryMultipliers = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true, TimeProvider timeProvider = null)
{
string connectionString = Configuration.GetConnectionString("AzureStorageConnectionString");
if (String.IsNullOrEmpty(connectionString))
Expand All @@ -31,6 +31,7 @@ protected override IQueue<SimpleWorkItem> GetQueue(int retries = 1, TimeSpan? wo
.RetryPolicy(retries <= 0 ? new NoRetry() : (IRetryPolicy)new ExponentialRetry(retryDelay.GetValueOrDefault(TimeSpan.FromMinutes(1)), retries))
.WorkItemTimeout(workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5)))
.DequeueInterval(TimeSpan.FromMilliseconds(100))
.TimeProvider(timeProvider)
.LoggerFactory(Log));
}

Expand Down

0 comments on commit d2405c9

Please sign in to comment.