Răsfoiți Sursa

[commands] Check if Oozie is enabled in desktop document cleanup (#3430)

Ying Chen 2 ani în urmă
părinte
comite
bb1b2163b6

+ 15 - 11
desktop/core/src/desktop/management/commands/desktop_document_cleanup.py

@@ -25,11 +25,14 @@ from beeswax.models import SavedQuery
 from beeswax.models import Session
 from datetime import date, timedelta
 from desktop.models import Document2
+from desktop.settings import INSTALLED_APPS
 from django.conf import settings
 from django.core.management.base import BaseCommand
 from django.db.utils import DatabaseError
 from importlib import import_module
-from oozie.models import Workflow
+
+if 'oozie' in INSTALLED_APPS:
+  from oozie.models import Workflow
 
 if sys.version_info[0] > 2:
   from django.utils.translation import gettext_lazy as _t, gettext as _
@@ -129,17 +132,18 @@ class Command(BaseCommand):
     # Clear out old Hive/Impala sessions
     self.objectCleanup(Session, 'status_code__gte', -10000, 'last_used')
 
-    # Clean out Trashed Workflows
-    try:
-      self.objectCleanup(Workflow, 'is_trashed', True, 'last_modified')
-    except NameError as NE:
-      LOG.info('Oozie app is not configured to clean out trashed workflows')
+    if 'oozie' in INSTALLED_APPS:  # check if oozie is enabled
+      # Clean out Trashed Workflows
+      try:
+        self.objectCleanup(Workflow, 'is_trashed', True, 'last_modified')
+      except NameError as NE:
+        LOG.info('Oozie app is not configured to clean out trashed workflows')
 
-    # Clean out Workflows without a name
-    try:
-      self.objectCleanup(Workflow, 'name', '', 'last_modified')
-    except NameError as NE:
-      LOG.info('Oozie app is not configured to clean out workflows without a name')
+      # Clean out Workflows without a name
+      try:
+        self.objectCleanup(Workflow, 'name', '', 'last_modified')
+      except NameError as NE:
+        LOG.info('Oozie app is not configured to clean out workflows without a name')
 
     # Clean out history Doc2 objects
     self.objectCleanup(Document2, 'is_history', True, 'last_modified')