Exemplo n.º 1
0
        public async Task BroadcastAsync(CancellationToken cancellationToken = default)
        {
            _logger.LogDebug("Finding cronjobs");
            List <CronjobWebhook> jobs;

            try
            {
                jobs = _cronjobWebhookProvider.Cronjobs.ToList();
                _logger.LogInformation($"Found {jobs.Count} cronjobs");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occurred while discovering cronjobs");
                throw;
            }

            if (!jobs.Any())
            {
                _logger.LogDebug("Cannot find any cronjobs");
                return;
            }

            var payload = new ProjectBatchRegistration
            {
                Title       = $"{_environment.ApplicationName} ({_environment.EnvironmentName})",
                Version     = _versionProvider.Version,
                Cronjobs    = jobs,
                Auth        = _options.Auth,
                TemplateKey = _options.TemplateKey,
            };

            await _cronjobApi.BatchRegisterProjectAsync(payload, cancellationToken);
        }
        public async Task BatchRegisterProjectAsync(ProjectBatchRegistration registration,
                                                    CancellationToken cancellationToken = default)
        {
            _logger.LogDebug("Sending registration payload");
            var json = JsonSerializer.Serialize(registration);
            var res  = await _httpClient.PostAsync(
                "projects/batchcreate",
                new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json),
                cancellationToken : cancellationToken
                );

            res.EnsureSuccessStatusCode();
        }