1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-08 19:47:44 +01:00

Added quartz support to the Billing project (#5186)

This commit is contained in:
Conner Turnbull 2024-12-23 11:56:05 -05:00 committed by GitHub
parent 11325c4d3f
commit adfe365db9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,13 @@
using Bit.Core.Jobs;
using Quartz;
namespace Bit.Billing.Jobs;
public class AliveJob(ILogger<AliveJob> logger) : BaseJob(logger)
{
protected override Task ExecuteJobAsync(IJobExecutionContext context)
{
_logger.LogInformation(Core.Constants.BypassFiltersEventId, null, "Billing service is alive!");
return Task.FromResult(0);
}
}

View File

@ -0,0 +1,36 @@
using Bit.Core.Jobs;
using Bit.Core.Settings;
using Quartz;
namespace Bit.Billing.Jobs;
public class JobsHostedService : BaseJobsHostedService
{
public JobsHostedService(
GlobalSettings globalSettings,
IServiceProvider serviceProvider,
ILogger<JobsHostedService> logger,
ILogger<JobListener> listenerLogger)
: base(globalSettings, serviceProvider, logger, listenerLogger) { }
public override async Task StartAsync(CancellationToken cancellationToken)
{
var everyTopOfTheHourTrigger = TriggerBuilder.Create()
.WithIdentity("EveryTopOfTheHourTrigger")
.StartNow()
.WithCronSchedule("0 0 * * * ?")
.Build();
Jobs = new List<Tuple<Type, ITrigger>>
{
new Tuple<Type, ITrigger>(typeof(AliveJob), everyTopOfTheHourTrigger)
};
await base.StartAsync(cancellationToken);
}
public static void AddJobsServices(IServiceCollection services)
{
services.AddTransient<AliveJob>();
}
}

View File

@ -100,6 +100,10 @@ public class Startup
services.AddScoped<IStripeFacade, StripeFacade>();
services.AddScoped<IStripeEventService, StripeEventService>();
services.AddScoped<IProviderEventService, ProviderEventService>();
// Jobs service
Jobs.JobsHostedService.AddJobsServices(services);
services.AddHostedService<Jobs.JobsHostedService>();
}
public void Configure(