def queue_pre_commit(func, key=None):
    """
    Queues a function to call before the transaction is committed. Use a
    key when you want to ensure that an action won't get triggered multiple
    times.

    Eg. you might want queue this function (lambda: validate_account(123))
    multiple times, but it only makes sense to run it once just before a
    transaction is committed. In this case, you could use the key
    'validate_account.123' to ensure it only runs once.

    """

    pre_commit_function_pool.queue(func, key=key)