Ejemplo n.º 1
0
        /// <summary>The process web error message.</summary>
        /// <param name="webApuResponse">The a.</param>
        private void ProcessWebErrorMessage(CrawlerMessages.WebApiErrorResponse webApuResponse)
        {
            try
            {
                _log.Debug($"retrying for: {webApuResponse.MergeObjectDto.DataId}");
                var mergeObject = webApuResponse.MergeObjectDto;
                var self        = Context.Self;

                _client.GetAsync(webApuResponse.url).ContinueWith(
                    response =>
                {
                    try
                    {
                        var webResponse = response.Result;
                        if (webResponse.StatusCode == HttpStatusCode.OK)
                        {
                            webResponse.Content.ReadAsAsync <WebApiResponseDto>()
                            .ContinueWith(
                                request => { return(new CrawlerMessages.PipedRequest(request.Result, mergeObject)); },
                                TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously)
                            .PipeTo(self);
                        }
                        else
                        {
                            // there is a connection but for any reason server response is not OK, so log that and
                            // do not retry that message
                            SendBadResponse(mergeObject, $"---Error:{webResponse.StatusCode.ToString()}---");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        _log.Error("Api connection error inner catch WebApiErrorResponse", e);
                    }

                    if (webApuResponse.attempt <= _systemConfiguration.HttpRetries)
                    {
                        self.Tell(
                            new CrawlerMessages.WebApiErrorResponse {
                            url = webApuResponse.url, MergeObjectDto = mergeObject, attempt = ++webApuResponse.attempt
                        });
                    }
                    else
                    {
                        SendBadResponse(mergeObject, $"--- NetworkIssue ---");
                    }
                });
            }
            catch (Exception e)
            {
                _log.Error($"cannot read api outer catch WebApiErrorResponse for:{webApuResponse.MergeObjectDto.DataId} ", e);
                SendBadResponse(webApuResponse.MergeObjectDto, _errorStatus);
            }
            finally
            {
                _lastActivity = DateTime.Now;
            }
        }