Jobs API#
Handle#
get_jobs_api#
Project.get_jobs_api()
Get the jobs api for the project.
Returns
JobsApi
: The Jobs Api handle
Configuration#
get_configuration#
JobsApi.get_configuration(type)
Get configuration for the specific job type.
Arguments
- type
str
: Type of the job. Currently, supported types include: SPARK, PYSPARK, PYTHON, DOCKER, FLINK.
Returns
dict
: Default job configuration
Raises
RestAPIError
: If unable to get the job configuration
Creation#
create_job#
JobsApi.create_job(name, config)
Create a new job.
import hopsworks
connection = hopsworks.connection()
project = connection.get_project()
jobs_api = project.get_jobs_api()
spark_config = jobs_api.get_configuration("PYSPARK")
spark_config['appPath'] = "/Resources/my_app.py"
job = jobs_api.create_job("my_spark_job", spark_config)
- name
str
: Name of the job. - config
dict
: Configuration of the job.
Returns
Job
: The Job object
Raises
RestAPIError
: If unable to create the job
Retrieval#
get_job#
JobsApi.get_job(name)
Get a job.
Arguments
- name
str
: Name of the job.
Returns
Job
: The Job object
Raises
RestAPIError
: If unable to get the job
get_jobs#
JobsApi.get_jobs()
Get all jobs.
Returns
List[Job]
: List of Job objects
Raises
RestAPIError
: If unable to get the jobs
Properties#
config#
Configuration for the job
creation_time#
Date of creation for the job
creator#
Creator of the job
id#
Id of the job
job_type#
Type of the job
name#
Name of the job
Methods#
delete#
Job.delete()
Delete the job
Potentially dangerous operation
This operation deletes the job and all executions.
Raises
RestAPIError
.
get_executions#
Job.get_executions()
Retrieves all executions for the job.
Returns
List[Execution]
Raises
RestAPIError
in case the backend fails to retrieve executions.
get_url#
Job.get_url()
run#
Job.run(args=None, await_termination=None)
Run the job, with the option of passing runtime arguments.
Example of a blocking execution and downloading logs once execution is finished.
# Run the job
execution = job.run(await_termination=True)
# True if job executed successfully
print(execution.success)
# Download logs
out_log_path, err_log_path = execution.download_logs()
- args
Optional[str]
: optional runtime arguments for the job - await_termination
Optional[bool]
: if True wait until termination is complete
Returns
Execution
. The execution object for the submitted run.
save#
Job.save()
Save the job.
This function should be called after changing a property such as the job configuration to save it persistently.
job.config['appPath'] = "Resources/my_app.py"
job.save()
Job
. The updated job object.