Skip to content

Jobs API#

Handle#

[source]

get_jobs_api#

Project.get_jobs_api()

Get the jobs api for the project.

Returns

JobsApi: The Jobs Api handle


Configuration#

[source]

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#

[source]

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)
Arguments

  • 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#

[source]

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

[source]

get_jobs#

JobsApi.get_jobs()

Get all jobs.

Returns

List[Job]: List of Job objects

Raises

  • RestAPIError: If unable to get the jobs

Properties#

[source]

config#

Configuration for the job


[source]

creation_time#

Date of creation for the job


[source]

creator#

Creator of the job


[source]

id#

Id of the job


[source]

job_type#

Type of the job


[source]

name#

Name of the job


Methods#

[source]

delete#

Job.delete()

Delete the job

Potentially dangerous operation

This operation deletes the job and all executions.

Raises

RestAPIError.


[source]

get_executions#

Job.get_executions()

Retrieves all executions for the job.

Returns

List[Execution]

Raises

RestAPIError in case the backend fails to retrieve executions.


[source]

get_url#

Job.get_url()

[source]

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()
Arguments

  • 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.


[source]

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()
Returns

Job. The updated job object.