"""
Author: <NAME>
Organization: terrestris GmbH & Co. KG
Contact: <EMAIL>
Created on: 10.11.20

"""

def runs_as_async_task() -> bool:
    """Check if a method is currently running in a worker.

    This method can be called in any method to check if this method
    was called from an async celery worker.

    Code taken from: https://stackoverflow.com/a/34335221

    Returns
        True, if method was called async. False otherwise.
    """
    from celery import current_task
    if not current_task:
        return False
    elif current_task.request.id is None:
        return False
    else:
        return True


"""
Author: <NAME>
Organization: terrestris GmbH & Co. KG
Contact: <EMAIL>
Created on: 10.11.20

"""

def runs_as_async_task() -> bool:
    """Check if a method is currently running in a worker.

    This method can be called in any method to check if this method
    was called from an async celery worker.

    Code taken from: https://stackoverflow.com/a/34335221

    Returns
        True, if method was called async. False otherwise.
    """
    from celery import current_task
    if not current_task:
        return False
    elif current_task.request.id is None:
        return False
    else:
        return True


Author: <NAME> Organization: terrestris GmbH & Co. KG Contact: <EMAIL> Created on: 10.11.20 Check if a method is currently running in a worker.      This method can be called in any method to check if this method     was called from an async celery worker.      Code taken from: https://stackoverflow.com/a/34335221      Returns         True, if method was called async. False otherwise.