def run_cron_with_cache_check(cron_class, force=False, silent=False): """ Checks the cache and runs the cron or not. @cron_class - cron class to run. """ cache = get_cache_by_name() if not cache.get(cron_class.__name__) or getattr(cron_class, 'ALLOW_PARALLEL_RUNS', False): timeout = DEFAULT_LOCK_TIME try: timeout = cron_class.DJANGO_CRON_LOCK_TIME if getattr(cron_class, 'DJANGO_CRON_LOCK_TIME', False) else settings.DJANGO_CRON_LOCK_TIME except: pass cache.set(cron_class.__name__, timezone.now(), timeout) try: instance = cron_class() CronJobManager.run(instance, force, silent) except: error = traceback.format_exc() print('Error running cron job, got exception:\n%s' % error) cache.delete(cron_class.__name__) else: if not silent: print("%s failed: lock has been found. Other cron started at %s" % (cron_class.__name__, cache.get(cron_class.__name__)))
def handle(self, *args, **options): for cron_class in CRONS_TO_RUN: if not cache.get(cron_class.__name__): instance = cron_class() timeout = DEFAULT_LOCK_TIME try: timeout = settings.DJANGO_CRON_LOCK_TIME except: pass cache.set(cron_class.__name__, timezone.now(), timeout) CronJobManager.run(instance, options['force']) cache.delete(cron_class.__name__) else: print "%s failed: lock has been found. Other cron started at %s" % (cron_class.__name__, cache.get(cron_class.__name__))
def handle(self, *args, **options): for cron_class in CRONS_TO_RUN: if not cache.get(cron_class.__name__): instance = cron_class() timeout = DEFAULT_LOCK_TIME try: timeout = settings.DJANGO_CRON_LOCK_TIME except: pass cache.set(cron_class.__name__, datetime.now(), timeout) CronJobManager.run(instance, options['force']) cache.delete(cron_class.__name__) else: print "%s failed: lock has been found. Other cron started at %s" % ( cron_class.__name__, cache.get(cron_class.__name__))
def run_cron_with_cache_check(cron_class, force=False, silent=False): """ Checks the cache and runs the cron or not. @cron_class - cron class to run. """ if not cache.get(cron_class.__name__) or getattr(cron_class, 'ALLOW_PARALLEL_RUNS', False): timeout = DEFAULT_LOCK_TIME try: timeout = settings.DJANGO_CRON_LOCK_TIME except: pass cache.set(cron_class.__name__, timezone.now(), timeout) instance = cron_class() CronJobManager.run(instance, force) cache.delete(cron_class.__name__) else: if not silent: print "%s failed: lock has been found. Other cron started at %s" % \ (cron_class.__name__, cache.get(cron_class.__name__))
def run_cron_with_cache_check(cron_class, force=False, silent=False): """ Checks the cache and runs the cron or not. @cron_class - cron class to run. """ if not cache.get(cron_class.__name__) or getattr(cron_class, 'ALLOW_PARALLEL_RUNS', False): timeout = DEFAULT_LOCK_TIME try: timeout = cron_class.DJANGO_CRON_LOCK_TIME if getattr(cron_class, 'DJANGO_CRON_LOCK_TIME', False) else settings.DJANGO_CRON_LOCK_TIME except: pass cache.set(cron_class.__name__, timezone.now(), timeout) instance = cron_class() CronJobManager.run(instance, force, silent) cache.delete(cron_class.__name__) else: if not silent: print("%s failed: lock has been found. Other cron started at %s" % \ (cron_class.__name__, cache.get(cron_class.__name__)))
def handle(self, *args, **options): for cron_class in CRONS_TO_RUN: instance = cron_class() CronJobManager.run(instance)