Skip to content

Commit 88fef5a

Browse files
committed
refactor(discovery): 优化实例注册逻辑处理
- 重构了元数据类型注册的处理流程,移除了空值检查的特殊处理逻辑 - 调整了IP类型和元数据类型的判断顺序,使代码逻辑更清晰 - 更新了Docker镜像版本号从v2.7.6到v2.7
1 parent 865e560 commit 88fef5a

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gateway等网关插件的高扩展性
99
### 通过docker运行
1010

1111
```bash
12-
docker run anjia0532/discovery-syncer-python:v2.7.6
12+
docker run anjia0532/discovery-syncer-python:v2.7.7
1313
```
1414

1515
特别的,`-c ` 支持配置远端http[s]的地址,比如读取静态资源的,比如读取nacos的

app/handler/discovery.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,10 @@ def discovery(discovery_name: Annotated[str, Path(title="discovery_name", descri
4343
for instance in discovery_instances:
4444
val = ""
4545
change = instance.enabled
46-
if registration.type == RegistrationType.METADATA:
47-
val = instance.metadata.get(registration.metadata_key, "")
48-
# 为了防止 metadata_key 为空,导致所有实例都下线,这里做个特殊处理
49-
if len(val) == 0:
50-
if registration.other_status != RegistrationStatus.ORIGIN:
51-
instance.enabled = registration.other_status == RegistrationStatus.UP
52-
instance.change = change != instance.enabled
53-
continue
54-
elif registration.type == RegistrationType.IP:
46+
if registration.type == RegistrationType.IP:
5547
val = instance.ip
48+
elif registration.type == RegistrationType.METADATA:
49+
val = instance.metadata.get(registration.metadata_key, "")
5650

5751
if re.match(registration.regexp_str or '', val):
5852
instance.enabled = registration.status == RegistrationStatus.UP

0 commit comments

Comments
 (0)