-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move DqtReportingService into Worker (#941)
- Loading branch information
Showing
15 changed files
with
206 additions
and
129 deletions.
There are no files selected for viewing
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
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
47 changes: 47 additions & 0 deletions
47
...rdSystem/src/TeachingRecordSystem.Core/Infrastructure/HostApplicationBuilderExtensions.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,47 @@ | ||
using Azure.Storage.Blobs; | ||
using Medallion.Threading; | ||
using Medallion.Threading.Azure; | ||
using Medallion.Threading.FileSystem; | ||
using Microsoft.Extensions.Azure; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace TeachingRecordSystem.Core.Infrastructure; | ||
|
||
public static class HostApplicationBuilderExtensions | ||
{ | ||
public static IHostApplicationBuilder AddDistributedLocks(this IHostApplicationBuilder builder) | ||
{ | ||
if (builder.Environment.IsProduction()) | ||
{ | ||
var containerName = builder.Configuration.GetRequiredValue("DistributedLockContainerName"); | ||
|
||
builder.Services.AddSingleton<IDistributedLockProvider>(sp => | ||
{ | ||
var blobServiceClient = sp.GetRequiredService<BlobServiceClient>(); | ||
var blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName); | ||
return new AzureBlobLeaseDistributedSynchronizationProvider(blobContainerClient); | ||
}); | ||
} | ||
else | ||
{ | ||
var lockFileDirectory = Path.Combine(Path.GetTempPath(), "qtlocks"); | ||
builder.Services.AddSingleton<IDistributedLockProvider>(new FileDistributedSynchronizationProvider(new DirectoryInfo(lockFileDirectory))); | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
public static IHostApplicationBuilder AddBlobStorage(this IHostApplicationBuilder builder) | ||
{ | ||
if (!builder.Environment.IsUnitTests()) | ||
{ | ||
builder.Services.AddAzureClients(clientBuilder => | ||
{ | ||
clientBuilder.AddBlobServiceClient(builder.Configuration.GetRequiredValue("StorageConnectionString")); | ||
}); | ||
} | ||
|
||
return builder; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
TeachingRecordSystem/src/TeachingRecordSystem.Core/ServiceCollectionExtensions.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,15 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TeachingRecordSystem.Core.Dqt; | ||
|
||
namespace TeachingRecordSystem.Core; | ||
|
||
public static partial class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddTrsBaseServices(this IServiceCollection services) | ||
{ | ||
return services | ||
.AddSingleton<IClock, Clock>() | ||
.AddCrmQueries() | ||
.AddSingleton<ReferenceDataCache>(); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
TeachingRecordSystem/src/TeachingRecordSystem.Worker/Program.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 |
---|---|---|
@@ -1,12 +1,58 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using TeachingRecordSystem; | ||
using TeachingRecordSystem.Core; | ||
using TeachingRecordSystem.Core.DataStore.Postgres; | ||
using TeachingRecordSystem.Core.Dqt.Services.CrmEntityChanges; | ||
using TeachingRecordSystem.Core.Dqt.Services.DqtReporting; | ||
using TeachingRecordSystem.Core.Infrastructure; | ||
using TeachingRecordSystem.Core.Infrastructure.Configuration; | ||
using TeachingRecordSystem.Worker.Infrastructure.Logging; | ||
|
||
var builder = Host.CreateApplicationBuilder(args); | ||
|
||
if (builder.Environment.IsProduction()) | ||
{ | ||
builder.Configuration.AddJsonEnvironmentVariable("AppConfig"); | ||
} | ||
|
||
builder.ConfigureLogging(); | ||
|
||
builder.Services.Configure<HostOptions>(o => o.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore); | ||
|
||
var pgConnectionString = builder.Configuration.GetRequiredValue("ConnectionStrings:DefaultConnection"); | ||
|
||
builder.Services.AddDbContext<TrsDbContext>( | ||
options => TrsDbContext.ConfigureOptions(options, pgConnectionString), | ||
contextLifetime: ServiceLifetime.Transient, | ||
optionsLifetime: ServiceLifetime.Singleton); | ||
|
||
builder.Services.AddDbContextFactory<TrsDbContext>(options => TrsDbContext.ConfigureOptions(options, pgConnectionString)); | ||
|
||
builder | ||
.AddBlobStorage() | ||
.AddDistributedLocks() | ||
.AddDqtReporting(); | ||
|
||
var crmServiceClient = new ServiceClient(builder.Configuration.GetRequiredValue("ConnectionStrings:Crm")) | ||
{ | ||
DisableCrossThreadSafeties = true, | ||
EnableAffinityCookie = true, | ||
MaxRetryCount = 2, | ||
RetryPauseTime = TimeSpan.FromSeconds(1) | ||
}; | ||
builder.Services.AddTransient<IOrganizationServiceAsync>(_ => crmServiceClient.Clone()); | ||
|
||
builder.Services | ||
.AddTrsBaseServices() | ||
.AddCrmEntityChanges(); | ||
|
||
// Filter telemetry emitted by DqtReportingService; | ||
// annoyingly we can't put this into the AddDqtReporting extension method since the method for adding Telemetry Processors | ||
// is different depending on whether you're in a Worker app or Web app :-/ | ||
builder.Services.AddApplicationInsightsTelemetryWorkerService() | ||
.AddApplicationInsightsTelemetryProcessor<IgnoreDependencyTelemetryProcessor>(); | ||
|
||
var host = builder.Build(); | ||
await host.RunAsync(); |
4 changes: 4 additions & 0 deletions
4
TeachingRecordSystem/src/TeachingRecordSystem.Worker/appsettings.Development.json
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
{ | ||
"DqtReporting": { | ||
"ProcessAllEntityTypesConcurrently": false | ||
}, | ||
"StorageConnectionString": "UseDevelopmentStorage=true" | ||
} |
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 |
---|---|---|
|
@@ -6,5 +6,8 @@ | |
"TeachingRecordSystem.Worker": "Warning" | ||
} | ||
} | ||
}, | ||
"DqtReporting": { | ||
"RunService": true | ||
} | ||
} |
Oops, something went wrong.