public async System.Threading.Tasks.Task <TaskKickResult> KickAsync(KickOptions opts)
        {
            var uriB = new UriBuilder("http", opts.Host, opts.Port, opts.Path);

            using var request = new HttpRequestMessage(HttpMethod.Post, uriB.Uri);

            if (opts.Headers != null)
            {
                foreach (var optsHeader in opts.Headers)
                {
                    request.Headers.Add(optsHeader.Key, optsHeader.Value);
                }
            }

            var response = await _httpClient.SendAsync(request);

            await using var readStream = await response.Content.ReadAsStreamAsync();

            byte[] respContentBuff = new byte[2000];
            var    read            = await readStream.ReadAsync(respContentBuff, 0, respContentBuff.Length);

            return(new TaskKickResult
            {
                Response = Encoding.UTF8.GetString(respContentBuff, 0, read),
                StatusCode = response.StatusCode
            });
        }
Example #2
0
        public async System.Threading.Tasks.Task Execute(IJobExecutionContext context)
        {
            var opts = JobOptions.FromJobDataMap(context.JobDetail.JobDataMap);

            try
            {
                var kickOptions = new KickOptions(opts);

                var response = await _taskKickerService.KickAsync(kickOptions);

                _logger.Action("Task kicked")
                .AndFactIs("job-id", opts.Id)
                .AndFactIs("task-resp", response)
                .Write();
            }
            catch (Exception e)
            {
                _logger.Error(e)
                .AndFactIs("job-id", opts.Id)
                .Write();
            }
        }