Exemple #1
0
def push_error_to_driver_through_redis(redis_client,
                                       error_type,
                                       message,
                                       job_id=None):
    """Push an error message to the driver to be printed in the background.

    Normally the push_error_to_driver function should be used. However, in some
    instances, the raylet client is not available, e.g., because the
    error happens in Python before the driver or worker has connected to the
    backend processes.

    Args:
        redis_client: The redis client to use.
        error_type (str): The type of the error.
        message (str): The message that will be printed in the background
            on the driver.
        job_id: The ID of the driver to push the error message to. If this
            is None, then the message will be pushed to all drivers.
    """
    if job_id is None:
        job_id = ray.JobID.nil()
    assert isinstance(job_id, ray.JobID)
    # Do everything in Python and through the Python Redis client instead
    # of through the raylet.
    error_data = gcs_utils.construct_error_message(job_id, error_type, message,
                                                   time.time())
    pubsub_msg = gcs_utils.PubSubMessage()
    pubsub_msg.id = job_id.binary()
    pubsub_msg.data = error_data
    redis_client.publish("ERROR_INFO:" + job_id.hex(),
                         pubsub_msg.SerializeToString())
Exemple #2
0
def publish_error_to_driver(
    error_type, message, job_id=None, redis_client=None, gcs_publisher=None
):
    """Push an error message to the driver to be printed in the background.

    Normally the push_error_to_driver function should be used. However, in some
    instances, the raylet client is not available, e.g., because the
    error happens in Python before the driver or worker has connected to the
    backend processes.

    Args:
        error_type (str): The type of the error.
        message (str): The message that will be printed in the background
            on the driver.
        job_id: The ID of the driver to push the error message to. If this
            is None, then the message will be pushed to all drivers.
        redis_client: The redis client to use.
        gcs_publisher: The GCS publisher to use. If specified, ignores
            redis_client.
    """
    if job_id is None:
        job_id = ray.JobID.nil()
    assert isinstance(job_id, ray.JobID)
    error_data = construct_error_message(job_id, error_type, message, time.time())
    if gcs_publisher:
        gcs_publisher.publish_error(job_id.hex().encode(), error_data)
    elif redis_client:
        pubsub_msg = gcs_utils.PubSubMessage()
        pubsub_msg.id = job_id.binary()
        pubsub_msg.data = error_data.SerializeToString()
        redis_client.publish(
            "ERROR_INFO:" + job_id.hex(), pubsub_msg.SerializeToString()
        )
    else:
        raise ValueError("One of redis_client and gcs_publisher needs to be specified!")