예제 #1
0
        private bool TryGetConfiguredUrl(out string?url)
        {
            url = Environment.GetEnvironmentVariable("GIT_POLICY_URL") ??
                  _git.GetConfig("policy.url", GitConfigurationScope.Global);

            return(!string.IsNullOrWhiteSpace(url));
        }
예제 #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            TimeSpan interval;
            string?  intervalStr = _git.GetConfig("policy.interval");

            if (!string.IsNullOrWhiteSpace(intervalStr) && int.TryParse(intervalStr, out int intervalSec))
            {
                interval = TimeSpan.FromSeconds(intervalSec);
            }
            else
            {
                interval = TimeSpan.FromMinutes(30);
            }

            _logger.LogInformation("Using polling interval of {0} seconds", interval.TotalSeconds);

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Syncing policies...");

                using Process proc = _git.CreateProcess("policy sync");
                proc.Start();
                proc.WaitForExit();

                if (proc.ExitCode != 0)
                {
                    _logger.LogError("Failed to sync policies (exit: {0})", proc.ExitCode);
                    _logger.LogError("stdout: {0}", proc.StandardOutput.ReadToEnd());
                    _logger.LogError("stderr: {0}", proc.StandardError.ReadToEnd());
                }
                else
                {
                    _logger.LogInformation("Policies synced OK");
                }

                try
                {
                    await Task.Delay(interval, stoppingToken);
                }
                catch (OperationCanceledException)
                {
                }
            }
        }