Skip to content

Commit

Permalink
Service to startup without schema initialized (#866)
Browse files Browse the repository at this point in the history
* Enable service to respond to schema apis

* Update indexDataStore instance

* Catch the particular exception
  • Loading branch information
rbans96 authored Jul 8, 2021
1 parent 1090a01 commit de3ad4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Microsoft.Health.Dicom.Core.Configs;
using Microsoft.Health.Dicom.Core.Exceptions;
using Microsoft.Health.Dicom.Core.Features.Store;

namespace Microsoft.Health.Dicom.Core.Features.HealthCheck
Expand Down Expand Up @@ -41,13 +42,20 @@ public BackgroundServiceHealthCheck(

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
Task<DateTimeOffset> oldestWaitingToBeDeleated = _backgroundServiceHealthCheckCache.GetOrAddOldestTimeAsync(_indexDataStore.GetOldestDeletedAsync, cancellationToken);
Task<int> numReachedMaxedRetry = _backgroundServiceHealthCheckCache.GetOrAddNumExhaustedDeletionAttemptsAsync(
t => _indexDataStore.RetrieveNumExhaustedDeletedInstanceAttemptsAsync(_deletedInstanceCleanupConfiguration.MaxRetries, t),
cancellationToken);
try
{
Task<DateTimeOffset> oldestWaitingToBeDeleated = _backgroundServiceHealthCheckCache.GetOrAddOldestTimeAsync(_indexDataStore.GetOldestDeletedAsync, cancellationToken);
Task<int> numReachedMaxedRetry = _backgroundServiceHealthCheckCache.GetOrAddNumExhaustedDeletionAttemptsAsync(
t => _indexDataStore.RetrieveNumExhaustedDeletedInstanceAttemptsAsync(_deletedInstanceCleanupConfiguration.MaxRetries, t),
cancellationToken);

_telemetryClient.GetMetric("Oldest-Requested-Deletion").TrackValue((await oldestWaitingToBeDeleated).ToUnixTimeSeconds());
_telemetryClient.GetMetric("Count-Deletions-Max-Retry").TrackValue(await numReachedMaxedRetry);
_telemetryClient.GetMetric("Oldest-Requested-Deletion").TrackValue((await oldestWaitingToBeDeleated).ToUnixTimeSeconds());
_telemetryClient.GetMetric("Count-Deletions-Max-Retry").TrackValue(await numReachedMaxedRetry);
}
catch (DataStoreException e) // This is expected when service is starting up without schema initialization
{
return HealthCheckResult.Unhealthy("Unhealthy service." + e.Message);
}

return HealthCheckResult.Healthy("Successfully computed values for background service.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public SqlIndexDataStoreFactory(SchemaInformation schemaInformation, IEnumerable

public IIndexDataStore GetInstance()
{
return _indexDataStores.First(store => (int)store.Version == _schemaInformation.Current.Value);
// if the service is starting without schema initialized
if (_schemaInformation.Current == null)
{
return _indexDataStores.First(store => (int)store.Version == _schemaInformation.MinimumSupportedVersion);
}

return _indexDataStores.FirstOrDefault(store => (int)store.Version == _schemaInformation.Current);
}
}
}

0 comments on commit de3ad4b

Please sign in to comment.