def publish_error_to_driver( error_type, message, gcs_publisher, 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: error_type (str): The type of the error. message (str): The message that will be printed in the background on the driver. gcs_publisher: The GCS publisher to use. 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) error_data = construct_error_message(job_id, error_type, message, time.time()) gcs_publisher.publish_error(job_id.hex().encode(), error_data)
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!")