public BuildAgent(ILogger logger, BuildServer.BuildServerClient buildServer, string apiKey, string workspacesDir, int maxJobs) { this.logger = logger; this.buildServer = buildServer; this.apiKey = apiKey; this.workspacesDir = workspacesDir; this.maxJobs = maxJobs; }
private static async Task <int> Main(string[] args) { string hostname = RequireEnvValue("HELIUM_CI_SERVER_HOST"); int port = RequireEnvValueInt("HELIUM_CI_SERVER_PORT"); string apiKey = RequireEnvValue("HELIUM_CI_AGENT_KEY"); int maxJobs = Environment.GetEnvironmentVariable("HELIUM_CI_AGENT_MAX_JOBS") is {} maxJobStr&& int.TryParse(maxJobStr, out var maxJobsInt) ? maxJobsInt : 1; var logger = LoggerFactory.Create(builder => { builder.SetMinimumLevel(LogLevel.Trace); builder.AddConsole(); }).CreateLogger("helium-agent"); foreach (var dir in Directory.GetDirectories(AgentWorkspacesDir)) { Directory.Delete(dir, recursive: true); } Console.WriteLine("Helium CI Agent"); Channel?channel = null; var cancel = new CancellationTokenSource(); Console.CancelKeyPress += (_, e) => { if (!cancel.IsCancellationRequested) { e.Cancel = true; cancel.Cancel(); channel?.ShutdownAsync(); } }; channel = new Channel(hostname, port, ChannelCredentials.Insecure); try { var client = new BuildServer.BuildServerClient(channel); var runner = new BuildAgent(logger, client, apiKey, AgentWorkspacesDir, maxJobs); await runner.JobLoop(cancel.Token); } catch (OperationCanceledException) {} finally { try { await channel.ShutdownAsync(); } catch {} } return(0); }