def upthendown_bounce(
    new_config,
    new_app_running,
    happy_new_tasks,
    old_app_live_tasks,
):
    """Starts a new app if necessary; only kills old apps once all the requested tasks for the new version are running.

    See the docstring for brutal_bounce() for parameters and return value.
    """
    if new_app_running and len(happy_new_tasks) == new_config['instances']:
        return {
            "create_app": False,
            # set.union doesn't like getting zero arguments
            "tasks_to_drain": set.union(set(), *old_app_live_tasks.values()),
        }
    else:
        return {
            "create_app": not new_app_running,
            "tasks_to_drain": set(),
        }