mirror of https://github.com/jumpserver/jumpserver
perf: 优化 task
parent
eebd6c30de
commit
dd15286d27
|
@ -143,10 +143,11 @@ class AssetsTaskMixin:
|
|||
data = serializer.validated_data
|
||||
assets = data.get("assets", [])
|
||||
asset_ids = [asset.id for asset in assets]
|
||||
|
||||
if data["action"] == "refresh":
|
||||
task = update_assets_hardware_info_manual.delay(asset_ids)
|
||||
task = update_assets_hardware_info_manual(asset_ids)
|
||||
else:
|
||||
task = test_assets_connectivity_manual.delay(asset_ids)
|
||||
task = test_assets_connectivity_manual(asset_ids)
|
||||
return task
|
||||
|
||||
def perform_create(self, serializer):
|
||||
|
|
|
@ -199,7 +199,7 @@ class Asset(NodesRelationMixin, AbsConnectivity, JMSOrgBaseModel):
|
|||
def primary_protocol(self):
|
||||
from assets.const.types import AllTypes
|
||||
primary_protocol_name = AllTypes.get_primary_protocol_name(self.category, self.type)
|
||||
protocol = self.protocols.get(name=primary_protocol_name)
|
||||
protocol = self.protocols.filter(name=primary_protocol_name).first()
|
||||
return protocol
|
||||
|
||||
@lazyproperty
|
||||
|
|
|
@ -45,11 +45,11 @@ def update_assets_hardware_info_manual(asset_ids):
|
|||
from assets.models import Asset
|
||||
assets = Asset.objects.filter(id__in=asset_ids)
|
||||
task_name = gettext_noop("Update assets hardware info: ")
|
||||
gather_assets_facts_task.delay(assets=assets, task_name=task_name)
|
||||
return gather_assets_facts_task.delay(assets=assets, task_name=task_name)
|
||||
|
||||
|
||||
def update_node_assets_hardware_info_manual(node_id):
|
||||
from assets.models import Node
|
||||
node = Node.objects.get(id=node_id)
|
||||
task_name = gettext_noop("Update node asset hardware information: ")
|
||||
gather_assets_facts_task.delay(nodes=[node], task_name=task_name)
|
||||
return gather_assets_facts_task.delay(nodes=[node], task_name=task_name)
|
||||
|
|
|
@ -32,7 +32,7 @@ def test_assets_connectivity_manual(asset_ids):
|
|||
from assets.models import Asset
|
||||
assets = Asset.objects.filter(id__in=asset_ids)
|
||||
task_name = gettext_noop("Test assets connectivity ")
|
||||
test_assets_connectivity_task.delay(assets, task_name)
|
||||
return test_assets_connectivity_task.delay(assets, task_name)
|
||||
|
||||
|
||||
def test_node_assets_connectivity_manual(node_id):
|
||||
|
@ -40,4 +40,4 @@ def test_node_assets_connectivity_manual(node_id):
|
|||
node = Node.objects.get(id=node_id)
|
||||
task_name = gettext_noop("Test if the assets under the node are connectable ")
|
||||
assets = node.get_all_assets()
|
||||
test_assets_connectivity_task.delay(*assets, task_name)
|
||||
return test_assets_connectivity_task.delay(*assets, task_name)
|
||||
|
|
Loading…
Reference in New Issue