Skip to content

Commit

Permalink
Adapt to SystemClock removal
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Aug 7, 2024
1 parent 7817524 commit 6579d49
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
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;

Check failure on line 23 in src/Foundatio.AzureStorage/Storage/AzureFileStorage.cs

View workflow job for this annotation

GitHub Actions / build / build

The type or namespace name 'TimeProvider' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in src/Foundatio.AzureStorage/Storage/AzureFileStorage.cs

View workflow job for this annotation

GitHub Actions / build / build

The type or namespace name 'TimeProvider' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in src/Foundatio.AzureStorage/Storage/AzureFileStorage.cs

View workflow job for this annotation

GitHub Actions / build / build

The type or namespace name 'TimeProvider' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in src/Foundatio.AzureStorage/Storage/AzureFileStorage.cs

View workflow job for this annotation

GitHub Actions / build / build

The type or namespace name 'TimeProvider' could not be found (are you missing a using directive or an assembly reference?)

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
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 6579d49

Please sign in to comment.