mirror of https://github.com/jumpserver/jumpserver
perf: Check whether the applet is available.
parent
1957c2983b
commit
805e7d1d5f
|
@ -200,7 +200,7 @@ class ConnectionToken(JMSOrgBaseModel):
|
|||
|
||||
host_account = applet.select_host_account(self.user, self.asset)
|
||||
if not host_account:
|
||||
raise JMSException({'error': 'No host account available'})
|
||||
raise JMSException({'error': 'No host account available, please check the applet, host and account'})
|
||||
|
||||
host, account, lock_key = bulk_get(host_account, ('host', 'account', 'lock_key'))
|
||||
gateway = host.domain.select_gateway() if host.domain else None
|
||||
|
|
|
@ -15,6 +15,7 @@ from assets.models import Platform
|
|||
from common.db.models import JMSBaseModel
|
||||
from common.utils import lazyproperty, get_logger
|
||||
from common.utils.yml import yaml_load_with_i18n
|
||||
from terminal.const import PublishStatus
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -278,7 +279,9 @@ class Applet(JMSBaseModel):
|
|||
if not host:
|
||||
return None
|
||||
logger.info('Select applet host: {}'.format(host.name))
|
||||
|
||||
if not self.is_available_on_host(host):
|
||||
logger.debug('No available applet {} for applet host: {}'.format(self.name, host.name))
|
||||
return None
|
||||
valid_accounts = host.accounts.all().filter(is_active=True, privileged=False)
|
||||
account = self.try_to_use_same_account(user, host)
|
||||
if not account:
|
||||
|
@ -311,6 +314,14 @@ class Applet(JMSBaseModel):
|
|||
platform.delete()
|
||||
return super().delete(using, keep_parents)
|
||||
|
||||
def is_available_on_host(self, host):
|
||||
publication = AppletPublication.objects.filter(applet=self, host=host).first()
|
||||
if not publication:
|
||||
return False
|
||||
if publication.status in [PublishStatus.pending, PublishStatus.failed]:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class AppletPublication(JMSBaseModel):
|
||||
applet = models.ForeignKey('Applet', on_delete=models.CASCADE, related_name='publications',
|
||||
|
|
Loading…
Reference in New Issue