1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-09 07:08:15 -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,6 +17,8 @@ namespace Bit.Jobs
public static void Main(string[] args)
{
var parameters = ParseParameters(args);
try
{
var host = new WebHostBuilder()
.UseContentRoot(parameters.ContainsKey("d") ? parameters["d"] : Directory.GetCurrentDirectory())
.UseStartup<Startup>()
@ -25,6 +27,15 @@ namespace Bit.Jobs
_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,6 +47,10 @@ namespace Bit.Jobs
return;
}
_logger.LogInformation("Starting job '{0}'.", parameters["j"]);
try
{
switch(parameters["j"])
{
case "validate-licenses":
@ -44,13 +59,19 @@ namespace Bit.Jobs
case "refresh-licenses":
// TODO
break;
case "hello":
_logger.LogInformation("Hello World!");
case "alive":
_logger.LogInformation(DateTime.UtcNow.ToString());
break;
default:
break;
}
}
catch(Exception e)
{
_logger.LogError(2, e, "Error performing job.");
throw e;
}
}
private static IDictionary<string, string> ParseParameters(string[] args)
{

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.