-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added distributed locks via a file share (#811)
- Loading branch information
1 parent
e48d1fb
commit 6849f19
Showing
6 changed files
with
138 additions
and
47 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
server/Tingle.Dependabot/Extensions/IServiceCollectionExtensions.cs
This file contains 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,52 @@ | ||
using Medallion.Threading; | ||
using Medallion.Threading.FileSystem; | ||
using Tingle.Dependabot.Workflow; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
/// <summary>Extensions on <see cref="IServiceCollection"/>.</summary> | ||
public static class IServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Add <see cref="IDistributedLockProvider"/>, a provider for <see cref="IDistributedLock"/>. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/> to be configured.</param> | ||
/// <param name="environment">The <see cref="IHostEnvironment"/> to use.</param> | ||
/// <param name="configuration">The root configuration instance from which to pull settings.</param> | ||
/// <returns></returns> | ||
public static IServiceCollection AddDistributedLockProvider(this IServiceCollection services, IHostEnvironment environment, IConfiguration configuration) | ||
{ | ||
var configKey = ConfigurationPath.Combine("DistributedLocking", "FilePath"); | ||
|
||
var path = configuration.GetValue<string?>(configKey); | ||
|
||
// when the path is null in development, set one | ||
if (string.IsNullOrWhiteSpace(path) && environment.IsDevelopment()) | ||
{ | ||
path = Path.Combine(environment.ContentRootPath, "distributed-locks"); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(path)) | ||
{ | ||
throw new InvalidOperationException($"'{nameof(path)}' must be provided via configuration at '{configKey}'."); | ||
} | ||
|
||
services.AddSingleton<IDistributedLockProvider>(new FileDistributedSynchronizationProvider(new(path))); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddWorkflowServices(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.Configure<WorkflowOptions>(configuration); | ||
services.ConfigureOptions<WorkflowConfigureOptions>(); | ||
|
||
services.AddSingleton<UpdateRunner>(); | ||
services.AddSingleton<UpdateScheduler>(); | ||
|
||
services.AddScoped<AzureDevOpsProvider>(); | ||
services.AddScoped<Synchronizer>(); | ||
|
||
return services; | ||
} | ||
} |
File renamed without changes.
This file contains 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 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 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 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