This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Migrate job to JsonConfig #550
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
10 changes: 10 additions & 0 deletions
10
src/NuGet.Jobs.Common/Configuration/SupportRequestDbConfiguration.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,10 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGet.Jobs.Configuration | ||
{ | ||
public class SupportRequestDbConfiguration : IDbConfiguration | ||
{ | ||
public string ConnectionString { get; set; } | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.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,28 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGet.SupportRequests.Notifications | ||
{ | ||
public class InitializationConfiguration | ||
{ | ||
/// <summary> | ||
/// Obsolete: replace with IcM configuration | ||
/// </summary> | ||
public string PagerDutyAccountName { get; set; } | ||
|
||
/// <summary> | ||
/// Obsolete: replace with IcM configuration | ||
/// </summary> | ||
public string PagerDutyApiKey { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code still uses PagerDuty. I can remove in follow-up PR, if it's not too time consuming. |
||
|
||
/// <summary> | ||
/// SMTP configuration. | ||
/// </summary> | ||
public string SmtpUri { get; set; } | ||
|
||
/// <summary> | ||
/// Email address to which the weekly report is sent. | ||
/// </summary> | ||
public string TargetEmailAddress { get; set; } | ||
} | ||
} |
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,36 +1,50 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Design; | ||
using System.Threading.Tasks; | ||
using Autofac; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using NuGet.Jobs; | ||
using NuGet.Jobs.Configuration; | ||
|
||
namespace NuGet.SupportRequests.Notifications | ||
{ | ||
internal class Job | ||
: JobBase | ||
: JsonConfigurationJob | ||
{ | ||
private IServiceContainer _serviceContainer; | ||
private IDictionary<string, string> _jobArgsDictionary; | ||
private InitializationConfiguration _configuration; | ||
private string _taskName; | ||
|
||
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary) | ||
{ | ||
if (!jobArgsDictionary.ContainsKey(JobArgumentNames.ScheduledTask)) | ||
{ | ||
throw new NotSupportedException("The required argument -Task is missing."); | ||
} | ||
base.Init(serviceContainer, jobArgsDictionary); | ||
|
||
_serviceContainer = serviceContainer ?? throw new ArgumentNullException(nameof(serviceContainer)); | ||
_jobArgsDictionary = jobArgsDictionary; | ||
_taskName = jobArgsDictionary[JobArgumentNames.ScheduledTask]; | ||
_configuration = _serviceProvider.GetRequiredService<IOptionsSnapshot<InitializationConfiguration>>().Value; | ||
} | ||
|
||
public override async Task Run() | ||
{ | ||
var scheduledTask = ScheduledTaskFactory.Create(_serviceContainer, _jobArgsDictionary, LoggerFactory); | ||
var scheduledTask = ScheduledTaskFactory.Create( | ||
_taskName, | ||
_configuration, | ||
OpenSqlConnectionAsync<SupportRequestDbConfiguration>, | ||
LoggerFactory); | ||
|
||
await scheduledTask.RunAsync(); | ||
} | ||
|
||
protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder) | ||
{ | ||
} | ||
|
||
protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) | ||
{ | ||
ConfigureInitializationSection<InitializationConfiguration>(services, configurationRoot); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Initialization": { | ||
"PagerDutyAccountName": "nuget", | ||
"PagerDutyApiKey": "$$Dev-PagerDuty-ApiKey$$", | ||
"SmtpUri": "#{Jobs.supportrequests.notifications.SmtpUri}", | ||
"TargetEmailAddress": "#{Jobs.supportrequests.notifications.weeklysummarynotification.TargetEmailAddress}" | ||
}, | ||
|
||
"SupportRequestDb": { | ||
"ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.SupportRequestDatabaseAddress};Initial Catalog=nuget-dev-supportrequest;User ID=$$Dev-SupportRequestDBWriter-UserName$$;Password=$$Dev-SupportRequestDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: we don't have DEV/INT enabled on Octopus, but I'm adding config in case we want to enable or to ease testing. I didn't want to add new DB creds to KeyVault, so these reference the existing writer credentials. This will change when AAD is configured. |
||
}, | ||
|
||
"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}", | ||
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}", | ||
"KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}", | ||
"KeyVault_ValidateCertificate": true, | ||
"KeyVault_StoreName": "My", | ||
"KeyVault_StoreLocation": "LocalMachine" | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing warnings due to partial dependencies upgrade in a previous PR. KeyVault and Sql libraries had been updated to
2.28.0
forValidation.Common.Job
, but notJobs.Common
.https://github.com/NuGet/NuGet.Jobs/blame/master/src/Validation.Common.Job/Validation.Common.Job.csproj#L106