perf: push dynamic user

pull/9133/head
feng 2022-11-29 19:05:45 +08:00
parent 6593648554
commit 52541d1dad
1 changed files with 7 additions and 4 deletions

View File

@ -12,11 +12,14 @@ __all__ = [
@org_aware_func("assets")
def push_accounts_to_assets_util(accounts, assets):
def push_accounts_to_assets_util(accounts, assets, username=None):
from assets.models import PushAccountAutomation
task_name = gettext_noop("Push accounts to assets")
task_name = PushAccountAutomation.generate_unique_name(task_name)
account_usernames = list(accounts.values_list('username', flat=True))
if username is None:
account_usernames = list(accounts.values_list('username', flat=True))
else:
account_usernames = [username]
data = {
'name': task_name,
@ -29,10 +32,10 @@ def push_accounts_to_assets_util(accounts, assets):
@shared_task(queue="ansible", verbose_name=_('Push accounts to assets'))
def push_accounts_to_assets(account_ids, asset_ids):
def push_accounts_to_assets(account_ids, asset_ids, username=None):
from assets.models import Asset, Account
with tmp_to_root_org():
assets = Asset.objects.filter(id__in=asset_ids)
accounts = Account.objects.filter(id__in=account_ids)
return push_accounts_to_assets_util(accounts, assets)
return push_accounts_to_assets_util(accounts, assets, username)