def serial_task(unique_key, default_retry_delay=30, timeout=5*60, max_retries=3,
                queue='background_queue'):
    def decorator(fn):
        # register task with celery.  Note that this still happens on import
        @task(bind=True, queue=queue, ignore_result=True,
              default_retry_delay=default_retry_delay, max_retries=max_retries)
        @wraps(fn)
        def _inner(self, *args, **kwargs):
            if settings.UNIT_TESTING:  # Don't depend on redis
                fn(*args, **kwargs)
                return

            client = get_redis_client()
            key = _get_unique_key(unique_key, fn, *args, **kwargs)
            lock = client.lock(key, timeout=timeout)
            if lock.acquire(blocking=False):
                try:
                    # Actually call the function
                    fn(*args, **kwargs)
                except Exception:
                    # Don't leave the lock around if the task fails
                    lock.release()
                    raise
                lock.release()
            else:
                msg = "Could not aquire lock '{}' for task '{}'.".format(
                    key, fn.__name__)
                self.retry(exc=CouldNotAqcuireLock(msg))
        return _inner
    return decorator
Prepares a value for use in a LIKE query.
dataset/ETHPy150Open dimagi/commcare-hq/corehq/util/decorators.py/serial_task--crossover with--dataset/ETHPy150Open dcramer/django-compositepks/django/db/backends/__init__.py/BaseDatabaseOperations.prep_for_like_query