-
Notifications
You must be signed in to change notification settings - Fork 1
APPT-2108: Lease factory introduce with async method #1648
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
Open
pata9
wants to merge
4
commits into
main
Choose a base branch
from
APPT-2108/leasing_factory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/api/Nhs.Appointments.Core/Concurrency/ILeaseManagerFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Nhs.Appointments.Core.Concurrency; | ||
|
|
||
| public interface ILeaseManagerFactory | ||
| { | ||
| ILeaseManager Create(string mode = null); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/api/Nhs.Appointments.Core/Concurrency/LeaseManagerFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| namespace Nhs.Appointments.Core.Concurrency; | ||
|
|
||
| public class LeaseManagerFactory : ILeaseManagerFactory | ||
| { | ||
| private readonly IEnumerable<ILeaseManager> _leaseManagers; | ||
|
|
||
| public LeaseManagerFactory(IEnumerable<ILeaseManager> leaseManagers) | ||
| { | ||
| _leaseManagers = leaseManagers; | ||
|
pata9 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public ILeaseManager Create(string mode = null) | ||
| { | ||
| if (string.IsNullOrEmpty(mode)) | ||
| { | ||
| return ResolveDefault(); | ||
| } | ||
|
|
||
| return _leaseManagers.SingleOrDefault(x => x.Mode.Equals(mode)) ?? throw new ArgumentException($"No lease manager found for mode: {mode}"); | ||
| } | ||
|
|
||
| private ILeaseManager ResolveDefault() => | ||
| _leaseManagers.SingleOrDefault(x => x.Mode.Equals(LeaseManagerMode.DistributedAzureBlob)) | ||
| ?? _leaseManagers.SingleOrDefault(x => x.Mode.Equals(LeaseManagerMode.InMemory)) | ||
| ?? throw new ArgumentException("No default lease manager found"); | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
src/api/Nhs.Appointments.Core/Concurrency/LeaseManagerMode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Nhs.Appointments.Core.Concurrency; | ||
|
|
||
| public static class LeaseManagerMode | ||
| { | ||
| public const string InMemory = "InMemory"; | ||
| public const string DistributedAzureBlob = "DistributedAzureBlob"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 22 additions & 10 deletions
32
src/api/Nhs.Appointments.Core/Concurrency/ServiceRegistration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,43 @@ | ||
| using Microsoft.Extensions.Azure; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Nhs.Appointments.Core.Blob; | ||
| using Nhs.Appointments.Core.Concurrency; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| public static class ServiceRegistration | ||
| { | ||
| public static IServiceCollection AddInMemoryLeasing(this IServiceCollection services) | ||
| public static IServiceCollection AddConcurrency(this IServiceCollection services, IConfiguration configuration) | ||
| { | ||
| services.Configure<LeaseManagerOptions>(opts => opts.Timeout = TimeSpan.FromSeconds(15)); | ||
| return services.AddSingleton<ILeaseManager, InMemoryLeaseManager>(); | ||
| var leaseManagerConnection = configuration.GetValue<string>("LEASE_MANAGER_CONNECTION"); | ||
|
|
||
| services | ||
| .AddTransient<ILeaseManagerFactory, LeaseManagerFactory>() | ||
| .Configure<LeaseManagerOptions>(opts => | ||
| { | ||
| opts.Timeout = | ||
| TimeSpan.FromSeconds(configuration.GetValue("LEASE_MANAGER_DEFAULT_TIME_OUT_SECONDS", 15)); | ||
| opts.Realm = configuration.GetValue("LEASE_MANAGER_DEFAULT_REALM", "leases"); | ||
| }) | ||
| .AddSingleton<ILeaseManager, InMemoryLeaseManager>(); | ||
|
|
||
| if (!string.IsNullOrEmpty(leaseManagerConnection)) | ||
| { | ||
| services.AddAzureBlobStoreLeasing(leaseManagerConnection); | ||
| } | ||
|
|
||
| return services; | ||
| } | ||
|
|
||
| public static IServiceCollection AddAzureBlobStoreLeasing(this IServiceCollection services, string connectionString, string containerName) | ||
| private static IServiceCollection AddAzureBlobStoreLeasing(this IServiceCollection services, string connectionString) | ||
| { | ||
| services.Configure<LeaseManagerOptions>(opts => { | ||
| opts.Timeout = TimeSpan.FromSeconds(30); | ||
| opts.ContainerName = containerName; | ||
| }); | ||
|
|
||
| services.AddAzureClients(x => | ||
| { | ||
| x.AddBlobServiceClient(connectionString); | ||
| }); | ||
|
|
||
| return services | ||
| .AddSingleton<IAzureBlobStorage, AzureBlobStorage>() | ||
| .AddSingleton<ILeaseManager, AzureStorageLeaseManager>(); | ||
| .AddTransient<ILeaseManager, AzureStorageLeaseManager>(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.