Exemple #1
0
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__)))
Exemple #2
0
 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__)) 
Exemple #3
0
 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__))
Exemple #5
0
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.
    @force      - run job even if not scheduled
    @silent     - suppress notifications
    """

    with CronJobManager(cron_class, silent) as manager:
        manager.run(force)
Exemple #6
0
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__)))
Exemple #7
0
def run_cron_with_cache_check(
    cron_class, force=False, silent=False, dry_run=False, stdout=None
):
    """
    Checks the cache and runs the cron or not.

    @cron_class - cron class to run.
    @force      - run job even if not scheduled
    @silent     - suppress notifications
    @dryrun     - don't actually perform the cron job
    @stdout     - where to write feedback to
    """
    with CronJobManager(cron_class, silent=silent, dry_run=dry_run, stdout=stdout) as manager:
        manager.run(force)
Exemple #8
0
 def handle(self, *args, **options):
     for cron_class in CRONS_TO_RUN:
         instance = cron_class()
         CronJobManager.run(instance)
Exemple #9
0
 def release(cls):
     silent = False
     with CronJobManager(cls, silent) as manager:
         lock = manager.lock_class(cls, manager.silent)
         lock.release()