Skip to main content

Job API Reference (Legacy)

Job API Reference (Legacy)

warning

These APIs are legacy and deprecated. Please use the current APIs instead.

Job SDK

The AnyscaleSDK class must be constructed in order to make calls to the SDK. This class allows you to create an authenticated client in which to use the SDK.

ParamTypeDescription
auth_tokenOptional StringAuthentication token used to verify you have permissions to access Anyscale. If not provided, permissions default to the credentials set for your current user. Credentials can be set by following the instructions on this page: https://console.anyscale.com/credentials

Example

from anyscale import AnyscaleSDK

sdk = AnyscaleSDK()

create_job

Create an Production Job

Parameters

NameTypeDescriptionNotes
create_production_jobCreateProductionJob

Returns ProductionjobResponse

get_production_job

Get an Production Job

Parameters

NameTypeDescriptionNotes
production_job_idstrDefaults to null

Returns ProductionjobResponse

terminate_job

Terminate an Production Job

Parameters

NameTypeDescriptionNotes
production_job_idstrDefaults to null

Returns ProductionjobResponse

fetch_job_logs

Retrieves logs for a Job.

This function may take several minutes if the Cluster this Job ran on has been terminated.

Returns the log output as a string.

Raises an Exception if fetching logs fails.

ParamTypeDescription
job_idStringID of the Job

Example

from anyscale import AnyscaleSDK

sdk = AnyscaleSDK(auth_token="sss_YourAuthToken")

job_logs = sdk.fetch_job_logs(job_id="job_id")

print(job_logs)

fetch_production_job_logs

Retrieves logs for a Production Job.

This function may take several minutes if the Cluster this Production Job ran on has been terminated.

Returns the log output as a string.

Raises an Exception if fetching logs fails.

ParamTypeDescription
job_idStringID of the Job

Example

from anyscale import AnyscaleSDK

sdk = AnyscaleSDK(auth_token="sss_YourAuthToken")

job_logs = sdk.fetch_production_job_logs(job_id="production_job_id")

print(job_logs)

get_job_logs_download

Parameters

NameTypeDescriptionNotes
job_idstrDefaults to null
all_logsoptional boolWhether to grab all logs.Defaults to true

Returns LogdownloadresultResponse

get_job_logs_stream

Parameters

NameTypeDescriptionNotes
job_idstrDefaults to null

Returns LogstreamResponse

search_jobs

DEPRECATED: This API is now deprecated. Use list_production_jobs instead.

Parameters

NameTypeDescriptionNotes
jobs_queryJobsQuery

Returns JobListResponse

list_production_jobs

Parameters

NameTypeDescriptionNotes
project_idoptional strproject_id to filter byDefaults to null
nameoptional strname to filter byDefaults to null
state_filterList[HaJobStates]A list of session states to filter byDefaults to []
creator_idoptional strfilter by creator idDefaults to null
paging_tokenoptional strDefaults to null
countoptional intDefaults to null

Returns ProductionjobListResponse

Job Models

BaseJobStatus

An enumeration.

Possible Values: ['RUNNING', 'COMPLETED', 'PENDING', 'STOPPED', 'SUCCEEDED', 'FAILED', 'UNKNOWN']

CreateClusterComputeConfig

Configuration of compute resources to use for launching a Cluster. Used when creating a cluster compute.

NameTypeDescriptionNotes
cloud_idstrThe ID of the Anyscale cloud to use for launching Clusters.[default to null]
maximum_uptime_minutesintIf set to a positive number, Anyscale will terminate the cluster this many minutes after cluster start.[optional] [default to null]
deployment_configsList[CloudDeploymentComputeConfig]A list of cloud deployment-specific configs to use.[optional] [default to null]
max_workersintDEPRECATED. This attribute will be ignored - please use the "max_resources" flag to configure resource limits.[optional] [default to null]
regionstrDeprecated! When creating a cluster compute, a region does not have to be provided. Instead we will use the value from the cloud.[optional] [default to USE_CLOUD]
allowed_azsList[str]The availability zones that sessions are allowed to be launched in, e.g. "us-west-2a". If not specified or "any" is provided as the option, any AZ may be used. If "any" is provided, it must be the only item in the list.[optional] [default to null]
head_node_typeComputeNodeTypeNode configuration to use for the head node.[default to null]
worker_node_typesList[WorkerNodeType]A list of node types to use for worker nodes.[optional] [default to null]
aws_advanced_configurations_jsonobject[DEPRECATED: use advanced_configurations_json instead] The advanced configuration json that we pass directly AWS APIs when launching an instance. We may do some validation on this json and reject the json if it is using a configuration that Anyscale does not support.[optional] [default to null]
gcp_advanced_configurations_jsonobject[DEPRECATED: use advanced_configurations_json instead] The advanced configuration json that we pass directly GCP APIs when launching an instance. We may do some validation on this json and reject the json if it is using a configuration that Anyscale does not support.[optional] [default to null]
advanced_configurations_jsonobjectAdvanced configurations for this compute node type to pass to the cloud provider when launching this instance.[optional] [default to null]
auto_select_worker_configboolIf set to true, worker node groups will automatically be selected based on workload.[optional] [default to false]
flagsobjectA set of advanced cluster-level flags that can be used to configure a particular workload.[optional] [default to null]
idle_termination_minutesintIf set to a positive number, Anyscale will terminate the cluster this many minutes after the cluster is idle. Idle time is defined as the time during which a Cluster is not running a user command or a Ray driver. Time spent running commands on Jupyter or ssh is still considered 'idle'. To disable, set this field to 0.[optional] [default to 120]

CreateJobQueueConfig

Specifies configuration of the job being added to a Job Queue

NameTypeDescriptionNotes
priorityintJob's relative priority (only relevant for Job Queues of type PRIORITY). Valid values range from 0 (highest) to +inf (lowest). Default value is None[optional] [default to null]
target_job_queue_idstrIdentifier of the existing Job Queue this job should be added to. Note, only one of `target_job_queue_id`, `target_job_queue_name` or `job_queue_spec` could be provided[optional] [default to null]
target_job_queue_namestrExisting Job Queue user-provided name (identifier), this job should be added to. Note, only one of `target_job_queue_id`, `target_job_queue_name` or `job_queue_spec` could be provided[optional] [default to null]
job_queue_specJobQueueSpecSpec of the Job Queue definition that should be created and associated with this job. Note, only one of `target_job_queue_id`, `target_job_queue_name` or `job_queue_spec` could be provided[optional] [default to null]

CreateProductionJob

NameTypeDescriptionNotes
namestrName of the job[default to null]
descriptionstrDescription of the job[optional] [default to null]
project_idstrId of the project this job will start clusters in[optional] [default to null]
configCreateProductionJobConfig[default to null]
job_queue_configCreateJobQueueConfigConfiguration specifying semantic of the execution using job queues[optional] [default to null]

CreateProductionJobConfig

NameTypeDescriptionNotes
entrypointstrA script that will be run to start your job.This command will be run in the root directory of the specified runtime env. Eg. 'python script.py'[optional] [default to ]
ray_serve_configobjectThe Ray Serve config to use for this Production service. This config defines your Ray Serve application, and will be passed directly to Ray Serve. You can learn more about Ray Serve config files here: https://docs.ray.io/en/latest/serve/production-guide/config.html[optional] [default to null]
runtime_envRayRuntimeEnvConfigA ray runtime env json. Your entrypoint will be run in the environment specified by this runtime env.[optional] [default to null]
build_idstrThe id of the cluster env build. This id will determine the docker image your job is run on.[default to null]
compute_config_idstrThe id of the compute configuration that you want to use. This id will specify the resources required for your job[optional] [default to null]
compute_configCreateClusterComputeConfigOne-off compute that the cluster will use.[optional] [default to null]
max_retriesintThe number of retries this job will attempt on failure. Set to None to set infinite retries[optional] [default to 5]
timeout_sintThe timeout in seconds for each job run. Set to None for no limit to be set[optional] [default to null]
runtime_env_configRayRuntimeEnvConfigDEPRECATED: Use runtime_env[optional] [default to null]

HaJobGoalStates

An enumeration.

Possible Values: ['SCHEDULED', 'RUNNING', 'TERMINATED', 'SUCCESS']

HaJobStates

An enumeration.

Possible Values: ['PENDING', 'AWAITING_CLUSTER_START', 'UPDATING', 'RUNNING', 'SUCCESS', 'ERRORED', 'TERMINATED', 'CLEANING_UP', 'BROKEN', 'OUT_OF_RETRIES', 'RESTARTING']

Job

NameTypeDescriptionNotes
idstrServer assigned unique identifier.[default to null]
ray_session_namestrName of the Session provided from Ray[default to null]
ray_job_idstrID of the Job provided from Ray[default to null]
namestrName of this Job.[optional] [default to null]
statusJobStatusStatus of this Job's execution.[default to null]
created_atdatetimeTime at which this Job was created.[default to null]
finished_atdatetimeTime at which this Job finished. If absent, this Job is still running.[optional] [default to null]
ray_job_submission_idstrID of the submitted Ray Job that this Job corresponds to.[optional] [default to null]
cluster_idstrID of the Anyscale Cluster this Job is on.[default to null]
namespace_idstrID of the Anyscale Namespace this Job is using.[optional] [default to DEPRECATED_NAMESPACE_ID]
runtime_environment_idstrID of the Anyscale Runtime Environment this Job is using.[default to null]
project_idstrID of the Project this Job belongs to.[optional] [default to null]
creator_idstrID of the user who created this Job.[default to null]

JobListResponse

A list response form the API. Contains a field "results" which has the contents of the response.

NameTypeDescriptionNotes
resultsList[Job][default to null]
metadataListResponseMetadata[optional] [default to null]

JobQueueConfig

Captures job's configuration in the context of its scheduling & execution via Job Queues

NameTypeDescriptionNotes
priorityintJob's relative priority (only relevant for Job Queues of type PRIORITY). Valid values range from 0 (highest) to +inf (lowest). Default value is None[optional] [default to null]

JobQueueExecutionMode

An enumeration.

Possible Values: ['FIFO', 'LIFO', 'PRIORITY']

JobQueueSpec

Specifies definition of the Job Queue to be created

NameTypeDescriptionNotes
job_queue_namestrOptional user-provided identifier of the queue that could be subsequently used to reference the queue when submitting jobs. Note that name has to be unique within the project.[optional] [default to null]
execution_modeJobQueueExecutionModeExecution mode of the jobs submitted into the queue (one of: FIFO,LIFO,PRIORITY[optional] [default to null]
compute_config_idstrThe id of the compute configuration that will be used to create cluster associated with the queue. Defaults to default compute config in the given project[optional] [default to null]
cluster_environment_build_idstrThe id of the cluster environment build that will be used to create cluster associated with the queue.[optional] [default to null]
max_concurrencyintMax number of jobs to be run concurrently. Defaults to 1, ie running no more than 1 job at a time.[optional] [default to 1]
idle_timeout_secintMax period of time queue will be accepting new jobs, before being sealed off and its associated cluster being shutdown[default to null]
auto_termination_threshold_job_countintMaximum number of jobs the cluster can run before it becomes eligible for termination.[optional] [default to null]

JobRunType

An enumeration.

Possible Values: ['INTERACTIVE_SESSION', 'RUN', 'RAY_SUBMIT']

JobStatus

An enumeration.

Possible Values: ['RUNNING', 'COMPLETED', 'PENDING', 'STOPPED', 'SUCCEEDED', 'FAILED', 'UNKNOWN']

JobsSortField

An enumeration.

Possible Values: ['STATUS', 'CREATED_AT', 'FINISHED_AT', 'NAME', 'ID']

ProductionJob

Model of a Production Job for use in the SDK.

NameTypeDescriptionNotes
idstrThe id of this job[default to null]
namestrName of the job[default to null]
descriptionstrDescription of the job[optional] [default to null]
created_atdatetimeThe time this job was created[default to null]
creator_idstrThe id of the user who created this job[default to null]
configProductionJobConfigThe config that was used to create this job[default to null]
job_queue_configJobQueueConfigJob Queue configuration of this job (if applicable)[optional] [default to null]
stateProductionJobStateTransitionThe current state of this job[default to null]
project_idstrId of the project this job will start clusters in[default to null]
last_job_run_idstrThe id of the last job run[optional] [default to null]
schedule_idstrIf the job was launched via Scheduled job, this will contain the id of that schedule.[optional] [default to null]
job_queue_idstrId of the job queue this job is being enqueued to[optional] [default to null]

ProductionJobConfig

NameTypeDescriptionNotes
entrypointstrA script that will be run to start your job.This command will be run in the root directory of the specified runtime env. Eg. 'python script.py'[optional] [default to ]
ray_serve_configobjectThe Ray Serve config to use for this Production service. This config defines your Ray Serve application, and will be passed directly to Ray Serve. You can learn more about Ray Serve config files here: https://docs.ray.io/en/latest/serve/production-guide/config.html[optional] [default to null]
runtime_envRayRuntimeEnvConfigA ray runtime env json. Your entrypoint will be run in the environment specified by this runtime env.[optional] [default to null]
build_idstrThe id of the cluster env build. This id will determine the docker image your job is run on.[default to null]
compute_config_idstrThe id of the compute configuration that you want to use. This id will specify the resources required for your job[default to null]
compute_configCreateClusterComputeConfigOne-off compute that the cluster will use.[optional] [default to null]
max_retriesintThe number of retries this job will attempt on failure. Set to None to set infinite retries[optional] [default to 5]
timeout_sintThe timeout in seconds for each job run. Set to None for no limit to be set[optional] [default to null]
runtime_env_configRayRuntimeEnvConfigDEPRECATED: Use runtime_env[optional] [default to null]

ProductionJobStateTransition

NameTypeDescriptionNotes
idstrThe id of this job state transition[default to null]
state_transitioned_atdatetimeThe last time the state of this job was updated[default to null]
current_stateHaJobStatesThe current state of the job[default to null]
goal_stateHaJobGoalStatesThe goal state of the job[optional] [default to null]
errorstrAn error message that occurred in this job state transition[optional] [default to null]
operation_messagestrThe logging message for this job state transition[optional] [default to null]
cluster_idstrThe id of the cluster the job is running on[optional] [default to null]

ProductionjobListResponse

A list response form the API. Contains a field "results" which has the contents of the response.

NameTypeDescriptionNotes
resultsList[ProductionJob][default to null]
metadataListResponseMetadata[optional] [default to null]

ProductionjobResponse

A response from the API. Contains a field "result" which has the contents of the response.

NameTypeDescriptionNotes
resultProductionJob[default to null]

RayRuntimeEnvConfig

A runtime env config. Can be used to start a production job.

NameTypeDescriptionNotes
working_dirstrThe working directory that your code will run in. Must be a remote URI like an s3 or git path.[optional] [default to null]
py_modulesList[str]Python modules that will be installed along with your runtime env. These must be remote URIs.[optional] [default to null]
relative_working_dirstrRelative path to the working directory that your code will run in. The appropriate cloud deployment object storage will be prepended to this path.[optional] [default to null]
relative_py_modulesList[str]Relative paths to python modules that will be installed along with your runtime env. The appropriate cloud deployment object storage will be prepended to these paths. If `py_modules` are specified, they will be also be installed.[optional] [default to null]
py_executablestrSpecifies the executable used for running the Ray workers. It can include arguments as well.[optional] [default to null]
pipList[str]A list of pip packages to install.[optional] [default to null]
condaobject[Union[Dict[str, Any], str]: Either the conda YAML config or the name of a local conda env (e.g., "pytorch_p36"),[optional] [default to null]
env_varsDict(str, str)Environment variables to set.[optional] [default to null]
configobjectConfig for runtime environment. Can be used to setup setup_timeout_seconds, the timeout of runtime environment creation.[optional] [default to null]
image_uristrSpecifies the image URI of the container in which the job will run.[optional] [default to null]

SortByClauseJobsSortField

This model is used in the backend to represent the SQL ORDER BY clauses.

NameTypeDescriptionNotes
sort_fieldJobsSortField[default to null]
sort_orderSortOrder[default to null]