1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 13:38:13 -05:00

cron logging

This commit is contained in:
Kyle Spearrin 2017-08-17 16:58:49 -04:00
parent fd35ac45b2
commit 4a25da5043
2 changed files with 42 additions and 20 deletions

View File

@ -17,14 +17,25 @@ namespace Bit.Jobs
public static void Main(string[] args)
{
var parameters = ParseParameters(args);
var host = new WebHostBuilder()
.UseContentRoot(parameters.ContainsKey("d") ? parameters["d"] : Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServer(new NoopServer())
.Build();
try
{
var host = new WebHostBuilder()
.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>();
_logger = host.Services.GetRequiredService<ILogger<Program>>();
_licensingService = host.Services.GetRequiredService<ILicensingService>();
}
catch(Exception e)
{
if(_logger != null)
{
_logger.LogCritical(1, e, "Error while bootstrapping.");
}
throw e;
}
MainAsync(parameters).Wait();
}
@ -36,19 +47,29 @@ namespace Bit.Jobs
return;
}
switch(parameters["j"])
_logger.LogInformation("Starting job '{0}'.", parameters["j"]);
try
{
case "validate-licenses":
await _licensingService.ValidateOrganizationsAsync();
break;
case "refresh-licenses":
// TODO
break;
case "hello":
_logger.LogInformation("Hello World!");
break;
default:
break;
switch(parameters["j"])
{
case "validate-licenses":
await _licensingService.ValidateOrganizationsAsync();
break;
case "refresh-licenses":
// TODO
break;
case "alive":
_logger.LogInformation(DateTime.UtcNow.ToString());
break;
default:
break;
}
}
catch(Exception e)
{
_logger.LogError(2, e, "Error performing job.");
throw e;
}
}

View File

@ -1,2 +1,3 @@
* * * * * root dotnet /jobs/Jobs.dll -d /jobs -j hello >> /var/log/cron.log 2>&1
0 * * * * root dotnet /jobs/Jobs.dll -d /jobs -j alive >> /var/log/cron.log 2>&1
0 */6 * * * root dotnet /jobs/Jobs.dll -d /jobs -j validate-licenses >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.