def get_and_check_tasks_for(context, task, msg_prefix=''):
    """Given a parent task, return the reason the parent task was spawned.

    ``.taskcluster.yml`` uses this to know whether to spawn an action,
    cron, or decision task definition.  ``tasks_for`` must be a valid one defined in the context.

    Args:
        task (dict): the task definition.
        msg_prefix (str): the string prefix to use for an exception.

    Raises:
        (KeyError, ValueError): on failure to find a valid ``tasks_for``.

    Returns:
        str: the ``tasks_for``

    """
    tasks_for = task['extra']['tasks_for']
    if tasks_for not in context.config['valid_tasks_for']:
        raise ValueError(
            '{}Unknown tasks_for: {}'.format(msg_prefix, tasks_for)
        )
    return tasks_for
Given a parent task, return the reason the parent task was spawned.

    ``.taskcluster.yml`` uses this to know whether to spawn an action,
    cron, or decision task definition.  ``tasks_for`` must be a valid one defined in the context.

    Args:
        task (dict): the task definition.
        msg_prefix (str): the string prefix to use for an exception.

    Raises:
        (KeyError, ValueError): on failure to find a valid ``tasks_for``.

    Returns:
        str: the ``tasks_for``