From f70ececa9d94ac1ccc68a2cb51b70490012a5d69 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 14 Feb 2019 10:18:27 -0500 Subject: [PATCH] get rid of premium renewal jobs for braintree --- src/Billing/Jobs/JobsHostedService.cs | 9 ++-- .../Jobs/PremiumRenewalRemindersJob.cs | 54 ------------------- src/Billing/Startup.cs | 6 +-- src/Core/Repositories/IUserRepository.cs | 1 - .../Repositories/SqlServer/UserRepository.cs | 12 ----- src/Sql/Sql.sqlproj | 1 - .../User_ReadByPremiumRenewal.sql | 23 -------- .../DbScripts/2019-01-31_00_Transactions.sql | 6 +++ 8 files changed, 13 insertions(+), 99 deletions(-) delete mode 100644 src/Billing/Jobs/PremiumRenewalRemindersJob.cs delete mode 100644 src/Sql/dbo/Stored Procedures/User_ReadByPremiumRenewal.sql diff --git a/src/Billing/Jobs/JobsHostedService.cs b/src/Billing/Jobs/JobsHostedService.cs index add82743f4..32a353a55e 100644 --- a/src/Billing/Jobs/JobsHostedService.cs +++ b/src/Billing/Jobs/JobsHostedService.cs @@ -26,17 +26,16 @@ namespace Bit.Billing.Jobs .WithCronSchedule("0 0 21 * * ?", x => x.InTimeZone(timeZone)) .Build(); - Jobs = new List> - { - new Tuple(typeof(PremiumRenewalRemindersJob), everyDayAtNinePmTrigger) - }; + Jobs = new List>(); + + // Add jobs here await base.StartAsync(cancellationToken); } public static void AddJobsServices(IServiceCollection services) { - services.AddTransient(); + // Register jobs here } } } diff --git a/src/Billing/Jobs/PremiumRenewalRemindersJob.cs b/src/Billing/Jobs/PremiumRenewalRemindersJob.cs deleted file mode 100644 index b87703821b..0000000000 --- a/src/Billing/Jobs/PremiumRenewalRemindersJob.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Bit.Core; -using Bit.Core.Jobs; -using Bit.Core.Repositories; -using Bit.Core.Services; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Quartz; - -namespace Bit.Billing.Jobs -{ - public class PremiumRenewalRemindersJob : BaseJob - { - private readonly BillingSettings _billingSettings; - private readonly GlobalSettings _globalSettings; - private readonly IUserRepository _userRepository; - private readonly IMailService _mailService; - private readonly IPaymentService _paymentService; - - public PremiumRenewalRemindersJob( - IOptions billingSettings, - GlobalSettings globalSettings, - IUserRepository userRepository, - IMailService mailService, - IPaymentService paymentService, - ILogger logger) - : base(logger) - { - _billingSettings = billingSettings?.Value; - _globalSettings = globalSettings; - _userRepository = userRepository; - _mailService = mailService; - _paymentService = paymentService; - } - - protected async override Task ExecuteJobAsync(IJobExecutionContext context) - { - var users = await _userRepository.GetManyByPremiumRenewalAsync(); - foreach(var user in users) - { - var upcomingInvoice = await _paymentService.GetUpcomingInvoiceAsync(user); - if(upcomingInvoice?.Date != null) - { - var items = new List { "1 × Premium Membership (Annually)" }; - await _mailService.SendInvoiceUpcomingAsync(user.Email, upcomingInvoice.Amount, - upcomingInvoice.Date.Value, items, false); - } - await _userRepository.UpdateRenewalReminderDateAsync(user.Id, DateTime.UtcNow); - } - } - } -} diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index 6e85974981..31f27c9eb3 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -62,9 +62,9 @@ namespace Bit.Billing }); services.Configure(options => options.LowercaseUrls = true); - // Jobs service - Jobs.JobsHostedService.AddJobsServices(services); - services.AddHostedService(); + // Jobs service, uncomment when we have some jobs to run + // Jobs.JobsHostedService.AddJobsServices(services); + // services.AddHostedService(); } public void Configure( diff --git a/src/Core/Repositories/IUserRepository.cs b/src/Core/Repositories/IUserRepository.cs index df16428461..61c57a3af2 100644 --- a/src/Core/Repositories/IUserRepository.cs +++ b/src/Core/Repositories/IUserRepository.cs @@ -12,7 +12,6 @@ namespace Bit.Core.Repositories Task GetKdfInformationByEmailAsync(string email); Task> SearchAsync(string email, int skip, int take); Task> GetManyByPremiumAsync(bool premium); - Task> GetManyByPremiumRenewalAsync(); Task GetPublicKeyAsync(Guid id); Task GetAccountRevisionDateAsync(Guid id); Task UpdateStorageAsync(Guid id); diff --git a/src/Core/Repositories/SqlServer/UserRepository.cs b/src/Core/Repositories/SqlServer/UserRepository.cs index 3bcecabba8..4a296ca1cd 100644 --- a/src/Core/Repositories/SqlServer/UserRepository.cs +++ b/src/Core/Repositories/SqlServer/UserRepository.cs @@ -78,18 +78,6 @@ namespace Bit.Core.Repositories.SqlServer } } - public async Task> GetManyByPremiumRenewalAsync() - { - using(var connection = new SqlConnection(ConnectionString)) - { - var results = await connection.QueryAsync( - "[dbo].[User_ReadByPremiumRenewal]", - commandType: CommandType.StoredProcedure); - - return results.ToList(); - } - } - public async Task GetPublicKeyAsync(Guid id) { using(var connection = new SqlConnection(ConnectionString)) diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj index b27395e88e..325551930e 100644 --- a/src/Sql/Sql.sqlproj +++ b/src/Sql/Sql.sqlproj @@ -224,7 +224,6 @@ - diff --git a/src/Sql/dbo/Stored Procedures/User_ReadByPremiumRenewal.sql b/src/Sql/dbo/Stored Procedures/User_ReadByPremiumRenewal.sql deleted file mode 100644 index d281a68046..0000000000 --- a/src/Sql/dbo/Stored Procedures/User_ReadByPremiumRenewal.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE PROCEDURE [dbo].[User_ReadByPremiumRenewal] -AS -BEGIN - SET NOCOUNT ON - - DECLARE @WindowRef DATETIME2(7) = GETUTCDATE() - DECLARE @WindowStart DATETIME2(7) = DATEADD (day, -15, @WindowRef) - DECLARE @WindowEnd DATETIME2(7) = DATEADD (day, 15, @WindowRef) - - SELECT - * - FROM - [dbo].[UserView] - WHERE - [Premium] = 1 - AND [PremiumExpirationDate] >= @WindowRef - AND [PremiumExpirationDate] < @WindowEnd - AND ( - [RenewalReminderDate] IS NULL - OR [RenewalReminderDate] < @WindowStart - ) - AND [Gateway] = 1 -- Braintree -END \ No newline at end of file diff --git a/util/Setup/DbScripts/2019-01-31_00_Transactions.sql b/util/Setup/DbScripts/2019-01-31_00_Transactions.sql index e9c61fd306..d113d86194 100644 --- a/util/Setup/DbScripts/2019-01-31_00_Transactions.sql +++ b/util/Setup/DbScripts/2019-01-31_00_Transactions.sql @@ -245,3 +245,9 @@ BEGIN AND [GatewayId] = @GatewayId END GO + +IF OBJECT_ID('[dbo].[User_ReadByPremiumRenewal]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_ReadByPremiumRenewal] +END +GO