Skip to content

Commit

Permalink
修复部分问题
Browse files Browse the repository at this point in the history
  • Loading branch information
anjia0532 committed May 8, 2024
1 parent 179803d commit fb95284
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gateway等网关插件的高扩展性
### 通过docker运行

```bash
docker run anjia0532/discovery-syncer-python:v2.4.2
docker run anjia0532/discovery-syncer-python:v2.4.3
```

特别的,`-c ` 支持配置远端http[s]的地址,比如读取静态资源的,比如读取nacos的
Expand Down Expand Up @@ -181,7 +181,7 @@ docker run -e SYNC_JOB_JSON=job.json \
-e DEFAULT_USER_EMAIL='discovery-syncer-python@syncer.org' \
-e DEFAULT_BASE_DIR='syncer' \
-v $(pwd)/job.json:/opt/discovery-syncer/job.json \
anjia0532/discovery-syncer-python-backup:v2.4.2
anjia0532/discovery-syncer-python-backup:v2.4.3
```

如果用命令行的话
Expand Down
12 changes: 6 additions & 6 deletions core/lib/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import json
import logging
import logging
import os
import socket
import sys
Expand Down Expand Up @@ -125,15 +125,15 @@ def emit(self, record):
f'此次离上次发送钉钉消息时间间隔不足 {self._time_interval} 秒,此次不发送这个钉钉内容: {record.msg}')

def __emit(self, record):
data = (DING_TALK_MSG_TEMPLATE or self._msg_template) % record.__dict__
try:
data = (DING_TALK_MSG_TEMPLATE or self._msg_template) % record.__dict__
data = data.replace("\\", "\\\\").replace("\\\\n", "\\n").replace("\"", "'")
# 因为钉钉发送也是使用requests实现的,如果requests调用的urllib3命名空间也加上了钉钉日志,将会造成循环,程序卡住。一般情况是在根日志加了钉钉handler。
self._remove_urllib_hanlder()
resp = requests.post(self._ding_talk_url + self.sign(),
json=json.loads(data.replace("\\", "\\\\").replace("\\\\n", "\\n")), timeout=(5, 5))
resp = requests.post(self._ding_talk_url + self.sign(), json=json.loads(data), timeout=(5, 5))
very_nb_print(f'钉钉返回 : {resp.text}')
except requests.RequestException as e:
very_nb_print(f"发送消息给钉钉机器人失败 {e}")
except Exception as e:
very_nb_print(f"发送消息给钉钉机器人失败,原始消息: {record.msg} {e}")

def __repr__(self):
level = logging.getLevelName(self.level)
Expand Down
4 changes: 2 additions & 2 deletions tools/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def check_file(file_path):
print(
f"\n\n下载 {syncer['syncer']}/gateway-api-to-file/{gateway}{config_dir}/{syncer['base_name']} ,status_code={status_code}, status_msg={status_msg}")
script_file.write(f"""
def restore_{job}_{gateway}():
def restore_{job.replace("-","_")}_{gateway.replace("-","_")}():
check_file("{job}/{gateway}/{syncer['base_name']}")
with open("{job}/{gateway}/{syncer['base_name']}", 'r', encoding='UTF-8') as f:
resp = httpx.put("{syncer['syncer']}/restore/{gateway}", content="\\n".join(f.readlines()),
Expand All @@ -132,7 +132,7 @@ def restore_{job}_{gateway}():
items = restore_job.split("_")
script_file.write(f"""
# 还原 {items[1]} 下的 {items[2]}
# {restore_job}
# {restore_job.replace("-","_")}
""")

print("执行 python restore.py 还原网关配置")
Expand Down

0 comments on commit fb95284

Please # to comment.