mirror of
https://github.com/bitwarden/server
synced 2025-12-18 01:03:17 +00:00
run jobs crons on API image
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -9,28 +12,31 @@ namespace Bit.Jobs
|
||||
public class Program
|
||||
{
|
||||
private static ILicensingService _licensingService;
|
||||
private static ILogger<Program> _logger;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var parameters = ParseParameters(args);
|
||||
var host = new WebHostBuilder()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseContentRoot(parameters.ContainsKey("d") ? parameters["d"] : Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>()
|
||||
.UseServer(new NoopServer())
|
||||
.Build();
|
||||
|
||||
_logger = host.Services.GetRequiredService<ILogger<Program>>();
|
||||
_licensingService = host.Services.GetRequiredService<ILicensingService>();
|
||||
|
||||
MainAsync(args).Wait();
|
||||
MainAsync(parameters).Wait();
|
||||
}
|
||||
|
||||
private async static Task MainAsync(string[] args)
|
||||
private async static Task MainAsync(IDictionary<string, string> parameters)
|
||||
{
|
||||
if(args.Length == 0)
|
||||
if(!parameters.ContainsKey("j"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch(args[0])
|
||||
switch(parameters["j"])
|
||||
{
|
||||
case "validate-licenses":
|
||||
await _licensingService.ValidateOrganizationsAsync();
|
||||
@@ -38,9 +44,28 @@ namespace Bit.Jobs
|
||||
case "refresh-licenses":
|
||||
// TODO
|
||||
break;
|
||||
case "hello":
|
||||
_logger.LogInformation("Hello World!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static IDictionary<string, string> ParseParameters(string[] args)
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
for(var i = 0; i < args.Length; i = i + 2)
|
||||
{
|
||||
if(!args[i].StartsWith("-"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dict.Add(args[i].Substring(1), args[i + 1]);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user