Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small improvements #271

Merged
merged 3 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/InformaticsGateway/Services/Connectors/PayloadAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,36 @@ private async void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
try
{
await _intializedTask.ConfigureAwait(false);

_timer.Enabled = false;
_logger.BucketsActive(_payloads.Count);
if (_payloads.Count > 0)
{
_logger.BucketsActive(_payloads.Count);
}
foreach (var key in _payloads.Keys)
{
_logger.BucketElapsedTime(key);
var payload = await _payloads[key].Task.ConfigureAwait(false);
using var loggerScope = _logger.BeginScope(new LoggingDataDictionary<string, object> { { "CorrelationId", payload.CorrelationId } });
if (payload.HasTimedOut)

if (payload.IsUploadCompleted())
{
if (_payloads.TryRemove(key, out _))
{
await QueueBucketForNotification(key, payload).ConfigureAwait(false);
}
else
{
_logger.BucketRemoveError(key);
}
}
else if (payload.HasTimedOut)
{
if (payload.AnyUploadFailures())
{
_payloads.TryRemove(key, out _);
_logger.PayloadRemovedWithFailureUploads(key);
}
else if (payload.IsUploadCompleted())
{
if (_payloads.TryRemove(key, out _))
{
await QueueBucketForNotification(key, payload).ConfigureAwait(false);
}
else
{
_logger.BucketRemoveError(key);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Threading;
using System.Threading.Tasks;
using Monai.Deploy.InformaticsGateway.Api.Storage;

namespace Monai.Deploy.InformaticsGateway.Services.Storage
Expand All @@ -36,6 +37,6 @@ internal interface IObjectUploadQueue
/// The default implementation blocks the call until a file is available from the queue.
/// </summary>
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
FileStorageMetadata Dequeue(CancellationToken cancellationToken);
Task<FileStorageMetadata> Dequeue(CancellationToken cancellationToken);
}
}
8 changes: 6 additions & 2 deletions src/InformaticsGateway/Services/Storage/ObjectUploadQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.GuardClauses;
using Microsoft.Extensions.Logging;
using Monai.Deploy.InformaticsGateway.Api.Storage;
Expand Down Expand Up @@ -47,7 +47,7 @@ public void Queue(FileStorageMetadata file)
_logger.InstanceAddedToUploadQueue(file.Id, _workItems.Count, process.WorkingSet64 / 1024.0);
}

public FileStorageMetadata Dequeue(CancellationToken cancellationToken)
public async Task<FileStorageMetadata> Dequeue(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
Expand All @@ -56,6 +56,10 @@ public FileStorageMetadata Dequeue(CancellationToken cancellationToken)
_logger.InstanceInUploadQueue(_workItems.Count);
return reuslt;
}
if (_workItems.IsEmpty)
{
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
}
}
throw new OperationCanceledException("Cancellation requested.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using Ardalis.GuardClauses;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -32,7 +31,6 @@
using Monai.Deploy.InformaticsGateway.Common;
using Monai.Deploy.InformaticsGateway.Configuration;
using Monai.Deploy.InformaticsGateway.Logging;
using Monai.Deploy.InformaticsGateway.Repositories;
using Monai.Deploy.InformaticsGateway.Services.Common;
using Monai.Deploy.Storage.API;
using Polly;
Expand Down Expand Up @@ -106,7 +104,7 @@ private async Task StartWorker(int thread, CancellationToken cancellationToken)
{
try
{
var item = _uplaodQueue.Dequeue(cancellationToken);
var item = await _uplaodQueue.Dequeue(cancellationToken);
await ProcessObject(item);
}
catch (OperationCanceledException ex)
Expand Down