public static ServerBuilder BuildServer(string[] args, TaskMonitor monitor) { var builder = new ServerBuilder(); builder.ConfigureAppConfiguration(config => { config.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .AddEnvironmentVariables() .AddCommandLine(args); }) .ConfigureLogging((config, l) => { var debugLevel = config.GetValue <Extensions.Logging.LogLevel>("Logging:Debug:LogLevel:Default", Extensions.Logging.LogLevel.Debug); l.AddConsole(config.GetSection("Logging").GetSection("Console")) .AddDebug(debugLevel); }) .ConfigureCloudOptions(c => c.GetSection("CloudOption").Get <CloudOption>()) .AddTaskItemSource(async(u, c, l, token) => new TaskItemSource( await u.GetOrCreateNodeDispatchQueueAsync(c.GetValue <string>(Constants.HpcHostNameEnv), token), TimeSpan.FromSeconds(u.Option.VisibleTimeoutSeconds), l)) .AddWorker(async(config, u, l, token) => new NodeAgentWorker( config, l, await u.GetOrCreateJobsTableAsync(token), await u.GetOrCreateNodesTableAsync(token), u)) .ConfigureWorker(w => ((NodeAgentWorker)w).Monitor = monitor); return(builder); }
static void Main(string[] args) { using (ServerBuilder builder = new ServerBuilder()) { builder.ConfigureAppConfiguration(config => { config.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appconfig.json", false, true) .AddEnvironmentVariables() .AddCommandLine(args); }) .ConfigureLogging((config, l) => { var debugLevel = config.GetValue <Extensions.Logging.LogLevel>("Logging:Debug:LogLevel:Default", Extensions.Logging.LogLevel.Debug); l.AddConsole(config.GetSection("Logging").GetSection("Console")) .AddDebug(debugLevel); }) .ConfigureCloudOptions(c => c.GetSection("CloudOption").Get <CloudOption>()) .AddTaskItemSource(async(u, c, l, token) => new TaskItemSource( await u.GetOrCreateJobDispatchQueueAsync(token), TimeSpan.FromSeconds(u.Option.VisibleTimeoutSeconds), l)) .AddWorker(async(config, u, l, token) => new JobDispatcherWorker( config, l, await u.GetOrCreateJobsTableAsync(token), u)); builder.BuildAndStart(); while (Console.In.Peek() == -1) { Task.Delay(1000).Wait(); } var logger = builder.LoggerFactory.CreateLogger <Program>(); logger.LogInformation("Stop message received, stopping"); builder.Stop(); } }