Commit 81408f10d6c6913e02d1293b5e6341edb3850f0e
1 parent
947b3dcf
Exists in
dev
Added some useful comments, mainly about Celery, and very small changes
Showing
6 changed files
with
55 additions
and
289 deletions
Show diff stats
simulators/plc/plcSimulator.py
... | ... | @@ -140,7 +140,7 @@ class PLCSimulator(Device, StatusManager): |
140 | 140 | i = 0 |
141 | 141 | |
142 | 142 | if (self.ended == 0): |
143 | - self.plcPrint("Not entry for telescope found in config file : " + self.config_file) | |
143 | + self.plcPrint("No entry for telescope found in config file : " + self.config_file) | |
144 | 144 | return (0) |
145 | 145 | while (True): |
146 | 146 | self.updateStatus(i) | ... | ... |
src/monitoring/tasks.py
1 | 1 | from __future__ import absolute_import |
2 | 2 | from django.conf import settings |
3 | 3 | from common.models import * |
4 | -from celery.task import Task | |
4 | + | |
5 | +# (EP) OLD task base class | |
6 | +#from celery.task import Task | |
7 | +# NEW task base class | |
8 | +from celery import Task | |
9 | + | |
5 | 10 | from devices.PLC import PLCController |
6 | 11 | from utils.JDManipulator import * |
7 | 12 | import json | ... | ... |
src/pyros/__init__.py
1 | -from __future__ import absolute_import | |
1 | +from __future__ import absolute_import, unicode_literals | |
2 | 2 | |
3 | +# This will make sure the app is always imported when | |
4 | +# Django starts so that shared_task will use this app. | |
3 | 5 | from .celery import app as celery_app |
4 | 6 | |
7 | +# EP : normalement, il faudrait ajouter cette ligne, à tester | |
8 | +#__all__ = ['celery_app'] | |
9 | + | |
10 | +# EP : normalement aussi, toutes ces autres lignes sont inutiles, à tester | |
11 | + | |
5 | 12 | from celery.signals import worker_ready |
6 | 13 | |
7 | 14 | from django.conf import settings | ... | ... |
src/pyros/celery.py
1 | -from __future__ import absolute_import | |
1 | +# First we import absolute_imports from the future, so that our celery.py module won’t clash with the library | |
2 | +from __future__ import absolute_import, unicode_literals | |
3 | + | |
2 | 4 | import os |
3 | 5 | from celery import Celery |
4 | 6 | |
5 | -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pyros.settings') | |
6 | - | |
7 | +# TODO: normalement, pas necessaire : a virer ? | |
7 | 8 | from django.conf import settings |
8 | 9 | |
10 | + | |
11 | +# Set the default DJANGO_SETTINGS_MODULE environment variable for the celery command-line program | |
12 | +# We don’t really need this line, but it saves us from always passing in the settings module to the celery program. | |
13 | +# It must always come before creating the app instances, as is what we do next | |
14 | +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pyros.settings') | |
15 | + | |
9 | 16 | app = Celery('pyros') |
10 | 17 | |
11 | -app.config_from_object('django.conf:settings') | |
18 | +# Using a string here means the worker doesn't have to serialize | |
19 | +# the configuration object to child processes. | |
20 | +# - namespace='CELERY' means all celery-related configuration keys | |
21 | +# should have a `CELERY_` prefix. | |
22 | +# EP modif: | |
23 | +#app.config_from_object('django.conf:settings') | |
24 | +app.config_from_object('django.conf:settings', namespace='CELERY') | |
25 | + | |
26 | + | |
27 | +''' Load task modules from all registered Django app configs. | |
28 | +This is a common practice for reusable apps : we define all tasks in a separate tasks.py module | |
29 | +(1 for each django app), and Celery autodiscovers them | |
30 | +''' | |
31 | +# EP : normalement, la 1ere ligne devrait suffire, à tester | |
32 | +#app.autodiscover_tasks() | |
12 | 33 | app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) |
34 | +''' Celery will automatically discover tasks from all our installed apps, following the tasks.py convention: | |
35 | +- app1/ | |
36 | + - tasks.py | |
37 | + - models.py | |
38 | +- app2/ | |
39 | + - tasks.py | |
40 | + - models.py | |
41 | + | |
42 | +This way we don’t have to manually add the individual modules to the CELERY_IMPORTS setting | |
43 | +''' | |
44 | + | |
13 | 45 | |
46 | +# Thisdebug_task example is a task that dumps its own request information. | |
47 | +# This is using the new bind=True task option introduced in Celery 3.1 | |
48 | +# to easily refer to the current task instance (with 'self') | |
14 | 49 | @app.task(bind=True) |
15 | 50 | def debug_task(self): |
16 | 51 | print("Request: {0!r}".format(self.request)) | ... | ... |
src/pyros/settings.py
src/pyros/settings.py.bak deleted
... | ... | @@ -1,282 +0,0 @@ |
1 | -""" | |
2 | -Django settings for pyros project. | |
3 | - | |
4 | -Generated by 'django-admin startproject' using Django 1.9.4. | |
5 | - | |
6 | -For more information on this file, see | |
7 | -https://docs.djangoproject.com/en/1.9/topics/settings/ | |
8 | - | |
9 | -For the full list of settings and their values, see | |
10 | -https://docs.djangoproject.com/en/1.9/ref/settings/ | |
11 | -""" | |
12 | - | |
13 | -# Dictionary containing all the versions for the different modules | |
14 | -# IMPORTANT : I must be updated at every commit ! | |
15 | - | |
16 | -MODULES_VERSIONS = { | |
17 | - "Alert Manager" : "0.2.4", | |
18 | - "Analyzer" : "0.1.2", | |
19 | - "Dashboard" : "0.1.1", | |
20 | - "Majordome" : "0.1.4", | |
21 | - "Monitoring" : "0.1.3", | |
22 | - "Observation Manager" : "0.1.3", | |
23 | - "Routine Manager" : "0.1.2", | |
24 | - "Scheduler" : "0.1.2", | |
25 | - "User Manager" : "0.1.1", | |
26 | - "Device" : "0.1.1" | |
27 | -} | |
28 | - | |
29 | -# Set MYSQL to False if you want to use SQLITE | |
30 | -# This line MUST NOT be changed at all except from changing True/False | |
31 | -# (or install_requirements script will become invalid) | |
32 | -MYSQL = True | |
33 | - | |
34 | -import os | |
35 | - | |
36 | -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | |
37 | -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
38 | - | |
39 | -# Output folder for images | |
40 | -OUTPUT_FOLDER = os.path.join(BASE_DIR, "../images_folder") | |
41 | - | |
42 | -# Quick-start development settings - unsuitable for production | |
43 | -# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ | |
44 | - | |
45 | -# SECURITY WARNING: keep the secret key used in production secret! | |
46 | -SECRET_KEY = '0*@w)$rq4x1c2w!c#gn58*$*u$w=s8uw2zpr_c3nj*u%qlxc23' | |
47 | - | |
48 | -# SECURITY WARNING: don't run with debug turned on in production! | |
49 | -DEBUG = True | |
50 | - | |
51 | -ALLOWED_HOSTS = ['localhost'] | |
52 | - | |
53 | - | |
54 | -# Application definition | |
55 | - | |
56 | -INSTALLED_APPS = [ | |
57 | - 'django.contrib.admin', | |
58 | - 'django.contrib.auth', | |
59 | - 'django.contrib.contenttypes', | |
60 | - 'django.contrib.sessions', | |
61 | - 'django.contrib.messages', | |
62 | - 'django.contrib.staticfiles', | |
63 | - | |
64 | - # for using "./manage.py graph_models" with graphviz: | |
65 | - # (https://projects.irap.omp.eu/projects/pyros/wiki/Project_Development#django-extensions-and-graphviz-useful-for-generating-an-image-of-all-the-models-and-their-relationships) | |
66 | - 'django_extensions', | |
67 | - 'test_without_migrations', | |
68 | - 'bootstrap3', | |
69 | - 'dashboard', | |
70 | - 'scheduler', | |
71 | - 'common', | |
72 | - 'alert_manager', | |
73 | - 'analyzer', | |
74 | - 'majordome', | |
75 | - 'monitoring', | |
76 | - 'observation_manager', | |
77 | - 'routine_manager', | |
78 | - 'user_manager', | |
79 | - 'devices' | |
80 | -] | |
81 | - | |
82 | -MIDDLEWARE_CLASSES = [ | |
83 | - 'django.middleware.security.SecurityMiddleware', | |
84 | - 'django.contrib.sessions.middleware.SessionMiddleware', | |
85 | - 'django.middleware.common.CommonMiddleware', | |
86 | - 'django.middleware.csrf.CsrfViewMiddleware', | |
87 | - 'django.contrib.auth.middleware.AuthenticationMiddleware', | |
88 | - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | |
89 | - 'django.contrib.messages.middleware.MessageMiddleware', | |
90 | - 'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
91 | -] | |
92 | - | |
93 | -ROOT_URLCONF = 'pyros.urls' | |
94 | - | |
95 | -TEMPLATES = [ | |
96 | - { | |
97 | - 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
98 | - 'DIRS': ['misc/templates'], | |
99 | - 'APP_DIRS': True, | |
100 | - 'OPTIONS': { | |
101 | - 'context_processors': [ | |
102 | - 'django.template.context_processors.debug', | |
103 | - 'django.template.context_processors.request', | |
104 | - 'django.contrib.auth.context_processors.auth', | |
105 | - 'django.contrib.messages.context_processors.messages', | |
106 | - ], | |
107 | - }, | |
108 | - }, | |
109 | -] | |
110 | - | |
111 | -WSGI_APPLICATION = 'pyros.wsgi.application' | |
112 | - | |
113 | -FIXTURE_DIRS = ( | |
114 | - 'misc/fixtures/', | |
115 | -) | |
116 | - | |
117 | -LOGIN_URL = "/" | |
118 | - | |
119 | -# FOR SIMULATOR -> do not touch this variable | |
120 | -SIMULATOR = True | |
121 | - | |
122 | -# FOR TESTS and SIMULATOR -> do not touch this variable | |
123 | -CELERY_TEST = False | |
124 | - | |
125 | -if not CELERY_TEST: | |
126 | - if not MYSQL: | |
127 | - DATABASES = { | |
128 | - 'default': { | |
129 | - 'ENGINE': 'django.db.backends.sqlite3', | |
130 | - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | |
131 | - } | |
132 | - } | |
133 | - else: | |
134 | - DATABASES = { | |
135 | - 'default': { | |
136 | - 'ENGINE': 'django.db.backends.mysql', | |
137 | - 'NAME': 'pyros', | |
138 | - 'USER': 'pyros', | |
139 | - 'PASSWORD': 'DjangoPyros', | |
140 | - } | |
141 | - } | |
142 | -else: | |
143 | - DATABASES = { | |
144 | - 'default': { | |
145 | - 'ENGINE': 'django.db.backends.mysql', | |
146 | - 'NAME': 'pyros_test', | |
147 | - 'USER': 'pyros', | |
148 | - 'PASSWORD': 'DjangoPyros' | |
149 | - } | |
150 | - } | |
151 | - | |
152 | -AUTH_USER_MODEL = 'common.PyrosUser' | |
153 | - | |
154 | -# Password validation | |
155 | -# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators | |
156 | - | |
157 | -AUTH_PASSWORD_VALIDATORS = [ | |
158 | - { | |
159 | - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | |
160 | - }, | |
161 | - { | |
162 | - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | |
163 | - }, | |
164 | - { | |
165 | - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | |
166 | - }, | |
167 | - { | |
168 | - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | |
169 | - }, | |
170 | -] | |
171 | - | |
172 | - | |
173 | -# Internationalization | |
174 | -# https://docs.djangoproject.com/en/1.9/topics/i18n/ | |
175 | - | |
176 | -LANGUAGE_CODE = 'en-us' | |
177 | - | |
178 | -TIME_ZONE = 'UTC' | |
179 | - | |
180 | -USE_I18N = True | |
181 | - | |
182 | -USE_L10N = True | |
183 | - | |
184 | -USE_TZ = True | |
185 | - | |
186 | - | |
187 | -# To find the media files {{ MEDIA_URL }} | |
188 | -MEDIA_URL = '/public/static/media/' | |
189 | - | |
190 | - | |
191 | -# To find the static files in the app/static/ap/... folders | |
192 | -STATIC_URL = '/public/static/' | |
193 | - | |
194 | -# To find the static files in src/static/. Any local directory can be added to this list. | |
195 | -STATICFILES_DIRS = ( | |
196 | - os.path.join(BASE_DIR, "misc", "static"), | |
197 | - ) | |
198 | - | |
199 | -# Used for deployment (DEBUG = False). Need to run "python manage.py collectstatic" to fill it. | |
200 | -STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'public', 'static') | |
201 | - | |
202 | - | |
203 | -# EP added | |
204 | -if not DEBUG: | |
205 | - ''' | |
206 | - CACHES = { | |
207 | - 'default': { | |
208 | - 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', | |
209 | - 'LOCATION': '127.0.0.1:11211', | |
210 | - } | |
211 | - } | |
212 | - ''' | |
213 | - CACHES = { | |
214 | - 'default': { | |
215 | - 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', | |
216 | - 'LOCATION': '/var/tmp/django_cache', | |
217 | - } | |
218 | - } | |
219 | - | |
220 | -else: | |
221 | - CACHES = { | |
222 | - 'default': { | |
223 | - 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', | |
224 | - } | |
225 | - } | |
226 | - | |
227 | -# from django.core.cache import cache | |
228 | -# cache.clear() | |
229 | - | |
230 | -# CELERY CONFIG | |
231 | - | |
232 | -# CELERY_RESULT_BACKEND = 'rpc://' | |
233 | -CELERY_RESULT_BACKEND = 'amqp' | |
234 | - | |
235 | -CELERY_ACCEPT_CONTENT = ['json'] | |
236 | -CELERY_TASK_SERIALIZER = 'json' | |
237 | -CELERY_RESULT_SERIALIZER = 'json' | |
238 | - | |
239 | -CELERY_IMPORTS = ( | |
240 | - "alert_manager.tasks", | |
241 | - "analyzer.tasks", | |
242 | - "majordome.tasks", | |
243 | - "monitoring.tasks", | |
244 | - "observation_manager.tasks", | |
245 | - "scheduler.tasks", | |
246 | -) | |
247 | - # "userSimulator.tasks", | |
248 | - | |
249 | -# This config allows only 1 process / queue. We replace it by the -c option at celery workers creation. | |
250 | -# CELERYD_CONCURRENCY = 1 | |
251 | - | |
252 | -''' Following config is needed for manual purge ''' | |
253 | -CELERY_ACKS_LATE = False | |
254 | -CELERYD_PREFETCH_MULTIPLIER = 1 | |
255 | - | |
256 | -CELERY_QUEUES = { | |
257 | - "alert_listener_q": {"exchange": "alert_listener_q", "routing_key": "alert_listener_q"}, | |
258 | - "monitoring_q": {"exchange": "monitoring_q", "routing_key": "monitoring_q"}, | |
259 | - "majordome_q": {"exchange": "majordome_q", "routing_key": "majordome_q"}, | |
260 | - "analysis_q": {"exchange": "analysis_q", "routing_key": "analysis_q"}, | |
261 | - "scheduling_q": {"exchange": "scheduling_q", "routing_key": "scheduling_q"}, | |
262 | - "create_calibrations_q": {"exchange": "create_calibrations_q", "routing_key": "create_calibrations_q"}, | |
263 | - "execute_plan_vis_q": {"exchange": "execute_plan_vis_q", "routing_key": "execute_plan_vis_q"}, | |
264 | - "execute_plan_nir_q": {"exchange": "execute_plan_nir_q", "routing_key": "execute_plan_nir_q"}, | |
265 | - "night_calibrations_q": {"exchange": "night_calibrations_q", "routing_key": "night_calibrations_q"}, | |
266 | -} | |
267 | - | |
268 | -CELERY_ROUTES = { | |
269 | - "alert_manager.tasks.AlertListener": {"queue": "alert_listener_q"}, | |
270 | - "majordome.tasks.Majordome": {"queue": "majordome_q"}, | |
271 | - "monitoring.tasks.Monitoring": {"queue": "monitoring_q"}, | |
272 | - "analyzer.tasks.analysis": {"queue": "analysis_q"}, | |
273 | - "observation_manager.tasks.execute_plan_vis": {"queue": "execute_plan_vis_q"}, | |
274 | - "observation_manager.tasks.execute_plan_nir": {"queue": "execute_plan_nir_q"}, | |
275 | - "observation_manager.tasks.create_calibrations": {"queue": "create_calibrations_q"}, | |
276 | - "observation_manager.tasks.night_calibrations": {"queue": "night_calibrations_q"}, | |
277 | - "scheduler.tasks.scheduling": {"queue": "scheduling_q"} | |
278 | -} | |
279 | - # "userSimulator.tasks.simulator": {"queue": "simulator_q"}, | |
280 | - | |
281 | -''' Removes pickle warning ''' | |
282 | -CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml'] |