pref: 修改 activity log (#9571)

* pref: 修改 activity log

* perf: 优化 acitivity

* pref: 修改 activity

* fix: 修复一些运行问题

* fix: app.py 中添加 tasks import

* fix: 添加 activity_callback

* fix: 添加 execute_account_backup_plan activity_callback

* fix: 添加 activity_callback -> gather_asset_accounts

* fix: 对 celery 任务添加 activity_callback 回调

* fix: 修改翻译

---------

Co-authored-by: ibuler <ibuler@qq.com>
Co-authored-by: jiangweidong <weidong.jiang@fit2cloud.com>
Co-authored-by: Bai <baijiangjie@gmail.com>
This commit is contained in:
fit2bot
2023-02-17 17:14:53 +08:00
committed by GitHub
parent 01c2e7128d
commit 9a62a7aaab
46 changed files with 700 additions and 653 deletions

View File

@@ -77,15 +77,10 @@ class AssetAccountHandler(BaseAccountHandler):
return filename
@classmethod
def create_data_map(cls, types: list):
def create_data_map(cls, accounts):
data_map = defaultdict(list)
# TODO 可以优化一下查询 在账号上做 category 的缓存 避免数据量大时连表操作
qs = Account.objects.filter(
asset__platform__type__in=types
).annotate(type=F('asset__platform__type'))
if not qs.exists():
if not accounts.exists():
return data_map
type_dict = {}
@@ -93,18 +88,18 @@ class AssetAccountHandler(BaseAccountHandler):
for j in i['children']:
type_dict[j['value']] = j['display_name']
header_fields = cls.get_header_fields(AccountSecretSerializer(qs.first()))
header_fields = cls.get_header_fields(AccountSecretSerializer(accounts.first()))
account_type_map = defaultdict(list)
for account in qs:
for account in accounts:
account_type_map[account.type].append(account)
data_map = {}
for tp, accounts in account_type_map.items():
for tp, _accounts in account_type_map.items():
sheet_name = type_dict.get(tp, tp)
data = AccountSecretSerializer(accounts, many=True).data
data = AccountSecretSerializer(_accounts, many=True).data
data_map.update(cls.add_rows(data, header_fields, sheet_name))
logger.info('\n\033[33m- 共收集 {} 条账号\033[0m'.format(qs.count()))
logger.info('\n\033[33m- 共备份 {} 条账号\033[0m'.format(accounts.count()))
return data_map
@@ -123,9 +118,8 @@ class AccountBackupHandler:
# Print task start date
time_start = time.time()
files = []
types = self.execution.types
data_map = AssetAccountHandler.create_data_map(types)
accounts = self.execution.backup_accounts
data_map = AssetAccountHandler.create_data_map(accounts)
if not data_map:
return files