1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-27 22:41:22 +01:00

run jobs on EST for cloud version

This commit is contained in:
Kyle Spearrin 2018-10-12 23:44:22 -04:00
parent 65e240c177
commit 52758e5749
2 changed files with 17 additions and 5 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Core;
using Bit.Core.Jobs; using Bit.Core.Jobs;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -11,25 +12,34 @@ namespace Bit.Admin.Jobs
{ {
public class JobsHostedService : BaseJobsHostedService public class JobsHostedService : BaseJobsHostedService
{ {
private readonly GlobalSettings _globalSettings;
public JobsHostedService( public JobsHostedService(
GlobalSettings globalSettings,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
ILogger<JobsHostedService> logger, ILogger<JobsHostedService> logger,
ILogger<JobListener> listenerLogger) ILogger<JobListener> listenerLogger)
: base(serviceProvider, logger, listenerLogger) { } : base(serviceProvider, logger, listenerLogger)
{
_globalSettings = globalSettings;
}
public override async Task StartAsync(CancellationToken cancellationToken) public override async Task StartAsync(CancellationToken cancellationToken)
{ {
var timeZone = _globalSettings.SelfHosted ? TimeZoneInfo.Utc :
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var everyFridayAt1145pmTrigger = TriggerBuilder.Create() var everyFridayAt1145pmTrigger = TriggerBuilder.Create()
.StartNow() .StartNow()
.WithCronSchedule("0 45 23 ? * FRI") .WithCronSchedule("0 45 23 ? * FRI", x => x.InTimeZone(timeZone))
.Build(); .Build();
var everySaturdayAtMidnightTrigger = TriggerBuilder.Create() var everySaturdayAtMidnightTrigger = TriggerBuilder.Create()
.StartNow() .StartNow()
.WithCronSchedule("0 0 0 ? * SAT") .WithCronSchedule("0 0 0 ? * SAT", x => x.InTimeZone(timeZone))
.Build(); .Build();
var everySundayAtMidnightTrigger = TriggerBuilder.Create() var everySundayAtMidnightTrigger = TriggerBuilder.Create()
.StartNow() .StartNow()
.WithCronSchedule("0 0 0 ? * SUN") .WithCronSchedule("0 0 0 ? * SUN", x => x.InTimeZone(timeZone))
.Build(); .Build();
Jobs = new List<Tuple<Type, ITrigger>> Jobs = new List<Tuple<Type, ITrigger>>

View File

@ -19,9 +19,11 @@ namespace Bit.Billing.Jobs
public override async Task StartAsync(CancellationToken cancellationToken) public override async Task StartAsync(CancellationToken cancellationToken)
{ {
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var everyDayAtNinePmTrigger = TriggerBuilder.Create() var everyDayAtNinePmTrigger = TriggerBuilder.Create()
.StartNow() .StartNow()
.WithCronSchedule("0 0 21 * * ?") .WithCronSchedule("0 0 21 * * ?", x => x.InTimeZone(timeZone))
.Build(); .Build();
Jobs = new List<Tuple<Type, ITrigger>> Jobs = new List<Tuple<Type, ITrigger>>