docs: def one_instance(function=None, key='', timeout=DEFAULT_ONE_INSTANCE_TIMEOUT):
      """
      Decorator to enforce only one Celery task execution at a time when multiple
      workers are available.
  
      See http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
      """
      def _dec(run_func):
          def _caller(*args, **kwargs):
              ret_value = None
              have_lock = False
              # Use Redis AOF for persistent lock.
              if REDIS_CLIENT.config_get('appendonly').values()[0] == 'no':
                  REDIS_CLIENT.config_set('appendonly', 'yes')
              lock = REDIS_CLIENT.lock(key, timeout=timeout)
              try:
                  logger.debug(
                      '%s: trying to acquire lock (PID %d).'
                      % (key, os.getpid()))
                  have_lock = lock.acquire(blocking=False)
                  if have_lock:
                      logger.debug(
                          '%s: acquired lock (PID %d).' % (key, os.getpid()))
                      ret_value = run_func(*args, **kwargs)
                  else:
                      logger.error(
                          '%s: did not acquire lock (PID %d).'
                          % (key, os.getpid()))
              finally:
                  if have_lock:
                      lock.release()
                      logger.debug(
                          '%s: released lock (PID %d).' % (key, os.getpid()))
              return ret_value
          return _caller
      return _dec(function) if function is not None else _dec