1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-18 11:38: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,14 +17,25 @@ namespace Bit.Jobs
public static void Main(string[] args) public static void Main(string[] args)
{ {
var parameters = ParseParameters(args); var parameters = ParseParameters(args);
var host = new WebHostBuilder() try
.UseContentRoot(parameters.ContainsKey("d") ? parameters["d"] : Directory.GetCurrentDirectory()) {
.UseStartup<Startup>() var host = new WebHostBuilder()
.UseServer(new NoopServer()) .UseContentRoot(parameters.ContainsKey("d") ? parameters["d"] : Directory.GetCurrentDirectory())
.Build(); .UseStartup<Startup>()
.UseServer(new NoopServer())
.Build();
_logger = host.Services.GetRequiredService<ILogger<Program>>(); _logger = host.Services.GetRequiredService<ILogger<Program>>();
_licensingService = host.Services.GetRequiredService<ILicensingService>(); _licensingService = host.Services.GetRequiredService<ILicensingService>();
}
catch(Exception e)
{
if(_logger != null)
{
_logger.LogCritical(1, e, "Error while bootstrapping.");
}
throw e;
}
MainAsync(parameters).Wait(); MainAsync(parameters).Wait();
} }
@ -36,19 +47,29 @@ namespace Bit.Jobs
return; return;
} }
switch(parameters["j"]) _logger.LogInformation("Starting job '{0}'.", parameters["j"]);
try
{ {
case "validate-licenses": switch(parameters["j"])
await _licensingService.ValidateOrganizationsAsync(); {
break; case "validate-licenses":
case "refresh-licenses": await _licensingService.ValidateOrganizationsAsync();
// TODO break;
break; case "refresh-licenses":
case "hello": // TODO
_logger.LogInformation("Hello World!"); break;
break; case "alive":
default: _logger.LogInformation(DateTime.UtcNow.ToString());
break; 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. # An empty line is required at the end of this file for a valid cron file.