Example #1
0
        private async Task <List <string> > CheckUpdateConfigStr(string probeUpdateString, bool isInitializingCacheList)
        {
            var parameters = new Dictionary <string, string>(2)
            {
                [Constants.PROBE_MODIFY_REQUEST] = probeUpdateString
            };

            var headers = new Dictionary <string, string>(2);

            headers["Long-Pulling-Timeout"] = _timeout.ToString();

            // told server do not hang me up if new initializing cacheData added in
            if (isInitializingCacheList)
            {
                headers["Long-Pulling-Timeout-No-Hangup"] = "true";
            }

            if (probeUpdateString.IsNullOrWhiteSpace())
            {
                return(new List <string>());
            }

            try
            {
                AssembleHttpParams(parameters, headers);

                // In order to prevent the server from handling the delay of the client's long task,
                // increase the client's read timeout to avoid this problem.
                long readTimeoutMs = _timeout + (long)Math.Round((_timeout >> 1) * 1d);

                var result = await _agent.HttpPost(Constants.CONFIG_CONTROLLER_PATH + "/listener", headers, parameters, "", readTimeoutMs);

                if (result.IsSuccessStatusCode)
                {
                    _isHealthServer = true;
                    var data = await result.Content.ReadAsStringAsync();

                    return(ParseUpdateDataIdResponse(data));
                }
                else
                {
                    _isHealthServer = false;
                    _logger?.LogError("[{0}] [check-update] get changed dataId error, code: {1}", _agent.GetName(), result.StatusCode.ToString());
                }
            }
            catch (Exception ex)
            {
                _isHealthServer = false;
                _logger?.LogError(ex, "[{0}] [check-update] get changed dataId exception", _agent.GetName());
                throw;
            }

            return(null);
        }