Using the Ray Job API
Overview
This section describes how to execute a complete Ray job process by calling an API, including running a Ray job, obtaining job details, and canceling a job.
This process assumes that the end tenant has been authorized on the console to use AI DataLake and has created a workspace, compute resource, and a RayJob endpoint. For how to call this API, see Calling an API.
Prerequisites
- The workspace ID of the Ray job to be executed has been obtained.
- The compute resources for running the job have been created.
- A Ray job endpoint for the job to be executed has been created, and the endpoint name has been obtained.
- The Ray job endpoint is in the Running state.
Running a Ray Job
- Request example
POST /v2/workspaces/{workspace_id}/ray-jobs
{workspace_id}: Workspace ID, which is used for resource isolation.
- Request body:
{ "name": "rayjob0615-4", "description": "description", "endpoint_name": "ray-test", "config": { "entrypoint": "python3 create_csv.py", "runtime_env": { "working_dir": "obs://ray-shared-csc/ray-zy/create_csv.zip", "pip": [ "numpy==1.16.1" ], "env_vars": { "additionalProp1": "value1", "additionalProp2": "value2", "additionalProp3": "value3" } }, "image": { "id": "dd877a59-5cbd-44c5-b8a7-dc464cca****", "image_version": "01ae8ee6-af8a-48a8-895b-8d4a70bf****" } } } - Response example
{ "job_id" : "ac8111bf-3601-xxxx-xxxx-b41d3e636a4e" }
Viewing Job Details
Call the API for viewing job details to view the complete configuration and execution result of a job.
- Request example
GET /v2/workspaces/{workspace_id}/ray-jobs/{job_id}
- {workspace_id}: Workspace ID, which is used for resource isolation.
- {job_id}: Job ID in the response body for Running a Ray Job.
- Response example
{ "name": "rayjob0615-4", "description": "description", "config": { "entrypoint": "python3 create_csv.py", "runtime_env":{ "working_dir":"obs://ray-shared-csc/ray-zy/create_csv.zip", "pip": [ "numpy==1.16.1" ], "env_vars": { "additionalProp1": "value1", "additionalProp2": "value2", "additionalProp3": "value3" } }, "image": { "id": "dd877a59-5cbd-44c5-b8a7-dc464cca****", "image_version": "01ae8ee6-af8a-48a8-895b-8d4a70bf****" } }, "endpoint_name": "ray-test", "status": "QUEUED" }
Canceling a Job Run
If a job needs to be terminated due to an execution exception, call the API for canceling a job run to cancel the job that is being executed. Only jobs in the QUEUED or RUNNING state can be canceled.
- Request example:
POST /v2/workspaces/{workspace_id}/ray-jobs/{job_id}/cancel
- {workspace_id}: Workspace ID, which is used for resource isolation.
- {job_id}: Job ID in the response body for Running a Ray Job.
- Response example
{ "job_id" : "ac8111bf-3601-xxxx-xxxx-b41d3e636a4e" }
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot