Эх сурвалжийг харах

HUE-3797 [task] Add a generic execute Django command task

Romain 6 жил өмнө
parent
commit
d4b19aee98

+ 13 - 12
desktop/core/src/desktop/celery.py

@@ -5,8 +5,7 @@ import os
 from celery import Celery
 from celery.schedules import crontab
 
-from desktop.settings import TIME_ZONE
-from desktop.conf import TASK_SERVER
+from desktop.settings import TIME_ZONE, INSTALLED_APPS
 
 
 # Set the default Django settings module for the 'celery' program.
@@ -30,13 +29,15 @@ def debug_task(self):
   print('Request: {0!r}'.format(self.request))
   return 'Hello'
 
-#
-if TASK_SERVER.BEAT_ENABLED.get():
-  app.conf.beat_schedule = {
-    'add-every-monday-morning': {
-      'task': 'desktop.celery.debug_task',
-      'schedule': crontab(minute='*'),
-      # 'schedule': crontab(hour=7, minute=30, day_of_week=1),
-      #'args': (16, 16),
-    },
-  }
+
+if 'django_celery_beat' in INSTALLED_APPS:
+  app.conf.beat_schedule = {}
+
+  if True:
+    app.conf.beat_schedule.update({
+      'add-every-monday-morning2': {
+        'task': 'desktop.celery.debug_task',
+        'schedule': crontab(minute='*'),
+        #'args': (16, 16),
+      },
+    })

+ 1 - 13
desktop/core/src/desktop/lib/scheduler/lib/beat.py

@@ -1,4 +1,5 @@
 
+
 from desktop.lib.scheduler.lib.base import Api
 
 
@@ -6,16 +7,3 @@ class CeleryBeatApi(Api):
 
   def __init__(self, user=None):
     pass
-
-
-from celery.schedules import crontab
-from desktop.celery import app
-
-app.conf.beat_schedule = {
-  'add-every-monday-morning': {
-    'task': 'desktop.celery.debug_task',
-    'schedule': crontab(minute='*/15'),
-    # 'schedule': crontab(hour=7, minute=30, day_of_week=1),
-    #'args': (16, 16),
-  },
-}

+ 16 - 0
desktop/core/src/desktop/lib/scheduler/tasks.py

@@ -0,0 +1,16 @@
+
+from desktop.celery import app
+
+
+'''
+Common utility tasks
+
+Example: generic run Django command install examples, document_clean-up, ldap_sync
+'''
+
+from notebook.management.commands.send_query_stats import Command
+
+
+@app.task(ignore_result=True)
+def execute_command(command_name):
+  pass

+ 0 - 2
desktop/core/src/desktop/management/commands/desktop_document_cleanup.py

@@ -151,5 +151,3 @@ class Command(BaseCommand):
         end = time.time()
         elapsed = (end - start)
         LOG.debug("Total time elapsed (seconds): %.2f" % elapsed)
-
-

+ 2 - 0
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -591,6 +591,7 @@ class ExecutionWrapper():
   def _until_available(self):
     if self.snippet['result']['handle'].get('sync', False):
       return # Request is already completed
+
     count = 0
     sleep_seconds = 1
     check_status_count = 0
@@ -622,6 +623,7 @@ class ExecutionWrapper():
       self.should_close = False
       self.api.close_statement(self.notebook, self.snippet)
 
+
 class ResultWrapper():
   def __init__(self, cols, rows, has_more):
     self._cols = cols

+ 1 - 1
desktop/libs/notebook/src/notebook/tasks.py

@@ -124,12 +124,12 @@ def close_statement_async(notebook, snippet, **kwargs):
 
 @app.task(ignore_result=True)
 def batch_execute_query(doc_id, user):
+  '''Independently run a query as a user and insert the result into another table.'''
   # get SQL
   # Add INSERT INTO table
   # Add variables?
   # execute query
   # return when done. send email notification. get taskid.
-
   # see in Flower API for listing runs?