diff --git a/colab/proxy/management/commands/import_proxy_data.py b/colab/proxy/management/commands/import_proxy_data.py index 960d9dd..c051c1b 100644 --- a/colab/proxy/management/commands/import_proxy_data.py +++ b/colab/proxy/management/commands/import_proxy_data.py @@ -2,6 +2,9 @@ import importlib import inspect +import logging +import os +import sys from django.core.management.base import BaseCommand from django.conf import settings @@ -12,7 +15,30 @@ from colab.proxy.utils.proxy_data_api import ProxyDataAPI class Command(BaseCommand): help = "Import proxy data into colab database" + lock_file = settings.IMPORT_DATA_LOCK_FILE + def handle(self, *args, **kwargs): + if os.path.exists(self.lock_file): + print(("This script is already running. " + "(If your are sure it's not please " + "delete the lock file in {}')").format(self.lock_file)) + sys.exit(1) + + if not os.path.exists(os.path.dirname(self.lock_file)): + os.mkdir(os.path.dirname(self.lock_file), 0755) + + run_lock = file(self.lock_file, 'w') + run_lock.close() + + try: + self.run() + except Exception as e: + logging.exception(e) + raise + finally: + os.remove(self.lock_file) + + def run(self): print "Executing extraction command..." for module_name in settings.PROXIED_APPS.keys(): diff --git a/colab/settings.py b/colab/settings.py index 17b964e..ac37629 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -251,6 +251,9 @@ MESSAGE_TAGS = { # Colab Settings COLAB_HOME_URL = '/dashboard' +# Plugins +IMPORT_DATA_LOCK_FILE = '/var/lock/colab/import_data.lock' + # Super Archives SUPER_ARCHIVES_PATH = '/var/lib/mailman/archives/private' SUPER_ARCHIVES_EXCLUDE = [] diff --git a/colab/super_archives/management/commands/import_emails.py b/colab/super_archives/management/commands/import_emails.py index 063f22f..fe653d6 100644 --- a/colab/super_archives/management/commands/import_emails.py +++ b/colab/super_archives/management/commands/import_emails.py @@ -270,7 +270,7 @@ class Command(BaseCommand, object): self.log(("This script is already running. " "(If your are sure it's not please " "delete the lock file in {}')").format(self.lock_file)) - sys.exit(0) + sys.exit(1) if not os.path.exists(os.path.dirname(self.lock_file)): os.mkdir(os.path.dirname(self.lock_file), 0755) -- libgit2 0.21.2