diff --git a/apps/terminal/models/applet/applet.py b/apps/terminal/models/applet/applet.py index ccd1a8e52..cfc496397 100644 --- a/apps/terminal/models/applet/applet.py +++ b/apps/terminal/models/applet/applet.py @@ -148,6 +148,11 @@ class Applet(JMSBaseModel): shutil.copytree(path, pkg_path) return instance, serializer + @classmethod + def clear_host_prefer(cls): + prefer_key = 'applet_host_prefer_{}'.format("*") + cache.delete_pattern(prefer_key) + def select_host(self, user, asset): hosts = self.hosts.filter(is_active=True) hosts = [host for host in hosts if host.load != 'offline'] diff --git a/apps/terminal/signal_handlers/applet.py b/apps/terminal/signal_handlers/applet.py index 3b1239901..db02f4b0c 100644 --- a/apps/terminal/signal_handlers/applet.py +++ b/apps/terminal/signal_handlers/applet.py @@ -20,6 +20,8 @@ logger = get_logger(__file__) def on_applet_host_create(sender, instance, created=False, **kwargs): if not created: return + Applet.clear_host_prefer() + applets = Applet.objects.all() instance.applets.set(applets)