summaryrefslogtreecommitdiffstats
path: root/pharos-dashboard/pharos_dashboard
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:11:58 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:11:58 +0200
commita1da09ca6e089913a6aacd5f55051a7f19d6f1fc (patch)
tree2b2a498a4eb0135bc99d03fe0e2aff2d6fbe8ab1 /pharos-dashboard/pharos_dashboard
parent79aec84973032e15ae9d36fcbd7d7d42af3283d1 (diff)
Implement periodic tasks
JIRA: RELENG-12 The dashboard is now querying jenkins periodically and saving the results in the database. This fixes delays that were caused by calling the jenkins API. Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/pharos_dashboard')
-rw-r--r--pharos-dashboard/pharos_dashboard/__init__.py3
-rw-r--r--pharos-dashboard/pharos_dashboard/celery.py20
-rw-r--r--pharos-dashboard/pharos_dashboard/settings.py15
3 files changed, 33 insertions, 5 deletions
diff --git a/pharos-dashboard/pharos_dashboard/__init__.py b/pharos-dashboard/pharos_dashboard/__init__.py
index e69de29..b6fc817 100644
--- a/pharos-dashboard/pharos_dashboard/__init__.py
+++ b/pharos-dashboard/pharos_dashboard/__init__.py
@@ -0,0 +1,3 @@
+# This will make sure the app is always imported when
+# Django starts so that shared_task will use this app.
+from .celery import app as celery_app # noqa
diff --git a/pharos-dashboard/pharos_dashboard/celery.py b/pharos-dashboard/pharos_dashboard/celery.py
new file mode 100644
index 0000000..4cf6a7a
--- /dev/null
+++ b/pharos-dashboard/pharos_dashboard/celery.py
@@ -0,0 +1,20 @@
+import os
+
+from celery import Celery
+
+# set the default Django settings module for the 'celery' program.
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pharos_dashboard.settings')
+
+from django.conf import settings # noqa
+
+app = Celery('pharos_dashboard')
+
+# Using a string here means the worker will not have to
+# pickle the object when using Windows.
+app.config_from_object('django.conf:settings')
+app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
+
+
+@app.task(bind=True)
+def debug_task(self):
+ print('Request: {0!r}'.format(self.request)) \ No newline at end of file
diff --git a/pharos-dashboard/pharos_dashboard/settings.py b/pharos-dashboard/pharos_dashboard/settings.py
index b6e9899..7717501 100644
--- a/pharos-dashboard/pharos_dashboard/settings.py
+++ b/pharos-dashboard/pharos_dashboard/settings.py
@@ -15,7 +15,6 @@ import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
@@ -27,7 +26,6 @@ DEBUG = True
ALLOWED_HOSTS = []
-
# Application definition
INSTALLED_APPS = [
@@ -43,6 +41,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django.contrib.humanize',
'bootstrap3',
+ 'djcelery',
+ 'kombu.transport.django',
]
MIDDLEWARE = [
@@ -77,7 +77,6 @@ TEMPLATES = [
WSGI_APPLICATION = 'pharos_dashboard.wsgi.application'
-
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
@@ -92,7 +91,6 @@ DATABASES = {
}
}
-
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
@@ -124,7 +122,6 @@ USE_L10N = True
USE_TZ = True
-
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
@@ -139,3 +136,11 @@ BOOTSTRAP3 = {
}
LOGIN_REDIRECT_URL = '/'
+
+import djcelery
+
+djcelery.setup_loader()
+# django broker, NOT SAFE FOR PRODUCTION
+BROKER_URL = 'django://'
+CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
+