diff --git a/horilla_automations/apps.py b/horilla_automations/apps.py index ab760462b..af60d2697 100644 --- a/horilla_automations/apps.py +++ b/horilla_automations/apps.py @@ -40,10 +40,15 @@ class HorillaAutomationConfig(AppConfig): model_choices[:] = list(set(model_choices)) # Update in-place # Only start automation when running the server - if ( - len(sys.argv) >= 2 - and sys.argv[1] == "runserver" - and os.environ.get("RUN_MAIN") == "true" + if not any( + cmd in sys.argv + for cmd in [ + "makemigrations", + "migrate", + "compilemessages", + "flush", + "shell", + ] ): from horilla_automations.signals import start_automation diff --git a/horilla_automations/views/views.py b/horilla_automations/views/views.py index dd74da212..defe04dfb 100644 --- a/horilla_automations/views/views.py +++ b/horilla_automations/views/views.py @@ -65,7 +65,19 @@ def refresh_automations(request): """ Method to refresh automation signals """ - REFRESH_METHODS["clear_connection"]() - REFRESH_METHODS["start_connection"]() - messages.success(request, "Automations refreshed") + refreshed = False + + if REFRESH_METHODS.get("clear_connection"): + REFRESH_METHODS["clear_connection"]() + refreshed = True + + if REFRESH_METHODS.get("start_connection"): + REFRESH_METHODS["start_connection"]() + refreshed = True + + if refreshed: + messages.success(request, "Automations refreshed successfully.") + else: + messages.error(request, "Automation method not available to refresh.") + return HorillaFormView.HttpResponse()