def _partition_non_idle()

in services/jenkins-autoscaling/lambda_mxnet_ci/autoscaling/handler.py [0:0]


def _partition_non_idle(node_objs):
    """
    Return nodes marked to be taken offline but still running a job. By design, nodes marked as offline are able to
    finish their scheduled jobs and don't get interrupted. This function filters nodes that got a job scheduled.
    :param node_objs: Jenkins nodes
    :return: 1. List of node_obj that are marked as offline and idling. 2. List of non-idle nodes
    """
    if not node_objs:
        return [], []

    # Update all objects before checking their content
    Parallel(n_jobs=min(JENKINS_PARALLEL_REQUESTS_LIMIT, len(node_objs)), backend="threading")(
        delayed(node_obj.poll)() for node_obj in node_objs)
    logging.debug("%d jenkins nodes updated", len(node_objs))

    new_node_objs = [node_obj for node_obj in node_objs if ((node_obj.is_idle()) and not node_obj.is_online())]
    non_idle_node_objs = [node_obj for node_obj in node_objs if ((not node_obj.is_idle()) or node_obj.is_online())]
    assert len(new_node_objs) + len(non_idle_node_objs) == len(node_objs)

    if non_idle_node_objs:
        logging.info('%s got a job scheduled while they are marked as offline - possible race condition',
                     ', '.join(str(o) for o in non_idle_node_objs))

    return new_node_objs, non_idle_node_objs