Commit a52454bb02d3909aa4731a29512d1ef12cd4bd63
Exists in
spb-release/3.0
Merge branch 'lock-proxy-imports' into 'spb-release/3.0'
Lock proxy imports See merge request !89
Showing
4 changed files
with
32 additions
and
1 deletions
Show diff stats
colab/proxy/management/commands/import_proxy_data.py
@@ -2,6 +2,9 @@ | @@ -2,6 +2,9 @@ | ||
2 | 2 | ||
3 | import importlib | 3 | import importlib |
4 | import inspect | 4 | import inspect |
5 | +import logging | ||
6 | +import os | ||
7 | +import sys | ||
5 | 8 | ||
6 | from django.core.management.base import BaseCommand | 9 | from django.core.management.base import BaseCommand |
7 | from django.conf import settings | 10 | from django.conf import settings |
@@ -12,7 +15,30 @@ from colab.proxy.utils.proxy_data_api import ProxyDataAPI | @@ -12,7 +15,30 @@ from colab.proxy.utils.proxy_data_api import ProxyDataAPI | ||
12 | class Command(BaseCommand): | 15 | class Command(BaseCommand): |
13 | help = "Import proxy data into colab database" | 16 | help = "Import proxy data into colab database" |
14 | 17 | ||
18 | + lock_file = settings.IMPORT_DATA_LOCK_FILE | ||
19 | + | ||
15 | def handle(self, *args, **kwargs): | 20 | def handle(self, *args, **kwargs): |
21 | + if os.path.exists(self.lock_file): | ||
22 | + print(("This script is already running. " | ||
23 | + "(If your are sure it's not please " | ||
24 | + "delete the lock file in {}')").format(self.lock_file)) | ||
25 | + sys.exit(1) | ||
26 | + | ||
27 | + if not os.path.exists(os.path.dirname(self.lock_file)): | ||
28 | + os.mkdir(os.path.dirname(self.lock_file), 0755) | ||
29 | + | ||
30 | + run_lock = file(self.lock_file, 'w') | ||
31 | + run_lock.close() | ||
32 | + | ||
33 | + try: | ||
34 | + self.run() | ||
35 | + except Exception as e: | ||
36 | + logging.exception(e) | ||
37 | + raise | ||
38 | + finally: | ||
39 | + os.remove(self.lock_file) | ||
40 | + | ||
41 | + def run(self): | ||
16 | print "Executing extraction command..." | 42 | print "Executing extraction command..." |
17 | 43 | ||
18 | for module_name in settings.PROXIED_APPS.keys(): | 44 | for module_name in settings.PROXIED_APPS.keys(): |
colab/settings.py
@@ -251,6 +251,9 @@ MESSAGE_TAGS = { | @@ -251,6 +251,9 @@ MESSAGE_TAGS = { | ||
251 | # Colab Settings | 251 | # Colab Settings |
252 | COLAB_HOME_URL = '/dashboard' | 252 | COLAB_HOME_URL = '/dashboard' |
253 | 253 | ||
254 | +# Plugins | ||
255 | +IMPORT_DATA_LOCK_FILE = '/var/lock/colab/import_data.lock' | ||
256 | + | ||
254 | # Super Archives | 257 | # Super Archives |
255 | SUPER_ARCHIVES_PATH = '/var/lib/mailman/archives/private' | 258 | SUPER_ARCHIVES_PATH = '/var/lib/mailman/archives/private' |
256 | SUPER_ARCHIVES_EXCLUDE = [] | 259 | SUPER_ARCHIVES_EXCLUDE = [] |
colab/super_archives/management/commands/import_emails.py
@@ -270,7 +270,7 @@ class Command(BaseCommand, object): | @@ -270,7 +270,7 @@ class Command(BaseCommand, object): | ||
270 | self.log(("This script is already running. " | 270 | self.log(("This script is already running. " |
271 | "(If your are sure it's not please " | 271 | "(If your are sure it's not please " |
272 | "delete the lock file in {}')").format(self.lock_file)) | 272 | "delete the lock file in {}')").format(self.lock_file)) |
273 | - sys.exit(0) | 273 | + sys.exit(1) |
274 | 274 | ||
275 | if not os.path.exists(os.path.dirname(self.lock_file)): | 275 | if not os.path.exists(os.path.dirname(self.lock_file)): |
276 | os.mkdir(os.path.dirname(self.lock_file), 0755) | 276 | os.mkdir(os.path.dirname(self.lock_file), 0755) |
misc/lib/systemd/system/colab.service
@@ -3,6 +3,8 @@ Description=Colab | @@ -3,6 +3,8 @@ Description=Colab | ||
3 | 3 | ||
4 | [Service] | 4 | [Service] |
5 | User=colab | 5 | User=colab |
6 | +ExecStartPre=/usr/bin/mkdir -p /var/lock/colab | ||
7 | +ExecStartPre=/usr/bin/chown -R colab:colab /var/lock/colab | ||
6 | ExecStart=/usr/lib/colab/bin/gunicorn colab.wsgi:application --bind=127.0.0.1:8001 --workers=3 | 8 | ExecStart=/usr/lib/colab/bin/gunicorn colab.wsgi:application --bind=127.0.0.1:8001 --workers=3 |
7 | Restart=on-failure | 9 | Restart=on-failure |
8 | 10 |