libs/celery_control.py
def safe_apply_async(a_task_for_a_celery_queue, *args, **kwargs):
    """ Enqueuing a new task, for which we use Celery's most flexible `apply_async` function,
    can fail deep inside amqp/transport.py with an OperationalError. Use this common wrapper to
    handle that case.

    An "a_task_for_a_celery_queue" is either a "@celery_app.task"-wrapped function' or it is a
    FalseCeleryApp. FalseCeleryApps implement an apply_async passthrough function that allows us to
    test "celery code" in the terminal. In the terminal everything is perfectly sequential and easy,
    without and devs don't need an active celery instance. """
    for i in range(10):
        try:
            return a_task_for_a_celery_queue.apply_async(*args, **kwargs)
        except OperationalError:
            # after 4+ years in production this strategy works perfectly.  Cool.
            if i >= 3:
                raise
 Enqueuing a new task, for which we use Celery's most flexible `apply_async` function,
    can fail deep inside amqp/transport.py with an OperationalError. Use this common wrapper to
    handle that case.

    An "a_task_for_a_celery_queue" is either a "@celery_app.task"-wrapped function' or it is a
    FalseCeleryApp. FalseCeleryApps implement an apply_async passthrough function that allows us to
    test "celery code" in the terminal. In the terminal everything is perfectly sequential and easy,
    without and devs don't need an active celery instance. 
Enqueuing a new task, for which we use Celery's most flexible `apply_async` function,
can fail deep inside amqp/transport.py with an OperationalError. Use this common wrapper to
handle that case.

An "a_task_for_a_celery_queue" is either a "@celery_app.task"-wrapped function' or it is a
FalseCeleryApp. FalseCeleryApps implement an apply_async passthrough function that allows us to
test "celery code" in the terminal. In the terminal everything is perfectly sequential and easy,
without and devs don't need an active celery instance.
Enqueuing a new task for which we use Celery ' s most flexible ` apply_async ` function can fail deep inside amqp / transport . py with an OperationalError . Use this common wrapper to handle that case . An " a_task_for_a_celery_queue " is either a " @celery_app . task " - wrapped function ' or it is a FalseCeleryApp . FalseCeleryApps implement an apply_async passthrough function that allows us to test " celery code " in the terminal . In the terminal everything is perfectly sequential and easy without and devs don ' t need an active celery instance .
def safe_apply_async(a_task_for_a_celery_queue, *args, **kwargs):
    for i in range(10):
        try:
            return a_task_for_a_celery_queue.apply_async(*args, **kwargs)
        except OperationalError:
            if i >= 3:
                raise
def safe_apply_async ( a_task_for_a_celery_queue , * args , ** kwargs ) : for i in range ( 10 ) : try : return a_task_for_a_celery_queue . apply_async ( * args , ** kwargs ) except OperationalError : if i >= 3 : raise
Enqueuing a new task, for which we use Celery's most flexible `apply_async` function,
can fail deep inside amqp/transport.py with an OperationalError.
Enqueuing a new task for which we use Celery ' s most flexible ` apply_async ` function can fail deep inside amqp / transport . py with an OperationalError .
""" Enqueuing a new task, for which we use Celery's most flexible `apply_async` function,
    can fail deep inside amqp/transport.py with an OperationalError. Use this common wrapper to
    handle that case.

    An "a_task_for_a_celery_queue" is either a "@celery_app.task"-wrapped function' or it is a
    FalseCeleryApp. FalseCeleryApps implement an apply_async passthrough function that allows us to
    test "celery code" in the terminal. In the terminal everything is perfectly sequential and easy,
    without and devs don't need an active celery instance. """ # after 4+ years in production this strategy works perfectly.  Cool.
a_task_for_a_celery_queue