fix: 修改db_port_mapper策略; 启动时进行check校验;

pull/9234/head
Bai 2022-12-21 18:38:29 +08:00 committed by Jiangjie.Bai
parent f4b0ba43a2
commit 5d865ffd54
2 changed files with 16 additions and 3 deletions

View File

@ -45,7 +45,7 @@ def on_applet_create(sender, instance, created=False, **kwargs):
def init_db_port_mapper(sender, **kwargs):
logger.info('Init db port mapper')
try:
db_port_manager.init()
db_port_manager.check()
except (ProgrammingError,) as e:
pass

View File

@ -34,9 +34,22 @@ class DBPortManager(object):
def magnus_listen_port_range(self):
return settings.MAGNUS_PORTS
def init(self):
@staticmethod
def fetch_dbs():
with tmp_to_root_org():
db_ids = Asset.objects.filter(platform__category=Category.DATABASE).values_list('id', flat=True)
dbs = Asset.objects.filter(platform__category=Category.DATABASE).order_by('id')
return dbs
def check(self):
dbs = self.fetch_dbs()
for db in dbs:
port = self.get_port_by_db(db, raise_exception=False)
if not port:
self.add(db)
def init(self):
dbs = self.fetch_dbs()
db_ids = dbs.values_list('id', flat=True)
db_ids = [str(i) for i in db_ids]
mapper = dict(zip(self.all_available_ports, list(db_ids)))
self.set_mapper(mapper)