nic-6443 commented on code in PR #12263:
URL: https://github.com/apache/apisix/pull/12263#discussion_r2156028963


##########
apisix/discovery/nacos/init.lua:
##########
@@ -15,410 +15,147 @@
 -- limitations under the License.
 --
 
-local require            = require
-local local_conf         = require('apisix.core.config_local').local_conf()
-local http               = require('resty.http')
-local core               = require('apisix.core')
-local ipairs             = ipairs
-local type               = type
-local math               = math
-local math_random        = math.random
-local ngx                = ngx
-local ngx_re             = require('ngx.re')
-local ngx_timer_at       = ngx.timer.at
-local ngx_timer_every    = ngx.timer.every
-local string             = string
-local string_sub         = string.sub
-local str_byte           = string.byte
-local str_find           = core.string.find
-local log                = core.log
+local core          = require("apisix.core")
+local nacos_factory = require("apisix.discovery.nacos.factory")
+local utils         = require("apisix.discovery.nacos.utils")
+local process       = require("ngx.process")
+local ipairs        = ipairs
+local require       = require
+local table         = require("apisix.core.table")
+local pcall         = pcall
+local ngx           = ngx
+
+local shdict_name = "nacos"
+
+local nacos_dict    = ngx.shared[shdict_name]
+local OLD_CONFIG_ID = utils.old_config_id
+local _M            = {}
 
-local default_weight
-local applications
-local auth_path = 'auth/login'
-local instance_list_path = 'ns/instance/list?healthyOnly=true&serviceName='
-local default_namespace_id = "public"
-local default_group_name = "DEFAULT_GROUP"
-local access_key
-local secret_key
-
-local events
-local events_list
-
-
-local _M = {}
-
-local function discovery_nacos_callback(data, event, source, pid)
-    applications = data
-    log.notice("update local variable application, event is: ", event,
-               "source: ", source, "server pid:", pid,
-               ", application: ", core.json.encode(applications, true))
-end
-
-
-local function request(request_uri, path, body, method, basic_auth)
-    local url = request_uri .. path
-    log.info('request url:', url)
-    local headers = {}
-    headers['Accept'] = 'application/json'
-
-    if basic_auth then
-        headers['Authorization'] = basic_auth
-    end
+function _M.nodes(service_name, discovery_args)
+    local ns_id = discovery_args and discovery_args.namespace_id or 
utils.default_namespace_id
+    local group_name = discovery_args and discovery_args.group_name or 
utils.default_group_name
+    local id = discovery_args and discovery_args.id or OLD_CONFIG_ID
+    local key = utils.generate_key(id,
+                                   ns_id,
+                                   group_name,
+                                   service_name)
+    local value = nacos_dict:get(key)
+    local nodes = {}
+    if not value then
+        -- maximum waiting time: 5 seconds
+        local waiting_time = 5
+        local step = 0.1
+        local logged = false
+        while not value and waiting_time > 0 do
+            if not logged then
+                logged = true
+            end
 
-    if body and 'table' == type(body) then
-        local err
-        body, err = core.json.encode(body)
-        if not body then
-            return nil, 'invalid body : ' .. err
+            ngx.sleep(step)
+            waiting_time = waiting_time - step
+            value = nacos_dict:get(key)

Review Comment:
   @Revolyssup why no any changes for this? 
https://github.com/apache/apisix/pull/12263#discussion_r2116198497, we already 
discuss to remove it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to