From 52758e5749c4cc8ffe45648fdc277af5d55326c6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 12 Oct 2018 23:44:22 -0400 Subject: [PATCH] run jobs on EST for cloud version --- src/Admin/Jobs/JobsHostedService.cs | 18 ++++++++++++++---- src/Billing/Jobs/JobsHostedService.cs | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Admin/Jobs/JobsHostedService.cs b/src/Admin/Jobs/JobsHostedService.cs index bca039a578..564bfb123d 100644 --- a/src/Admin/Jobs/JobsHostedService.cs +++ b/src/Admin/Jobs/JobsHostedService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Bit.Core; using Bit.Core.Jobs; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -11,25 +12,34 @@ namespace Bit.Admin.Jobs { public class JobsHostedService : BaseJobsHostedService { + private readonly GlobalSettings _globalSettings; + public JobsHostedService( + GlobalSettings globalSettings, IServiceProvider serviceProvider, ILogger logger, ILogger listenerLogger) - : base(serviceProvider, logger, listenerLogger) { } + : base(serviceProvider, logger, listenerLogger) + { + _globalSettings = globalSettings; + } public override async Task StartAsync(CancellationToken cancellationToken) { + var timeZone = _globalSettings.SelfHosted ? TimeZoneInfo.Utc : + TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); + var everyFridayAt1145pmTrigger = TriggerBuilder.Create() .StartNow() - .WithCronSchedule("0 45 23 ? * FRI") + .WithCronSchedule("0 45 23 ? * FRI", x => x.InTimeZone(timeZone)) .Build(); var everySaturdayAtMidnightTrigger = TriggerBuilder.Create() .StartNow() - .WithCronSchedule("0 0 0 ? * SAT") + .WithCronSchedule("0 0 0 ? * SAT", x => x.InTimeZone(timeZone)) .Build(); var everySundayAtMidnightTrigger = TriggerBuilder.Create() .StartNow() - .WithCronSchedule("0 0 0 ? * SUN") + .WithCronSchedule("0 0 0 ? * SUN", x => x.InTimeZone(timeZone)) .Build(); Jobs = new List> diff --git a/src/Billing/Jobs/JobsHostedService.cs b/src/Billing/Jobs/JobsHostedService.cs index cc5a2faa16..add82743f4 100644 --- a/src/Billing/Jobs/JobsHostedService.cs +++ b/src/Billing/Jobs/JobsHostedService.cs @@ -19,9 +19,11 @@ namespace Bit.Billing.Jobs public override async Task StartAsync(CancellationToken cancellationToken) { + var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); + var everyDayAtNinePmTrigger = TriggerBuilder.Create() .StartNow() - .WithCronSchedule("0 0 21 * * ?") + .WithCronSchedule("0 0 21 * * ?", x => x.InTimeZone(timeZone)) .Build(); Jobs = new List>