Skip to content

Commit 8a9a5c3

Browse files
authored
job list types (#389)
Adds ability to list jobs by type.
1 parent 290e9f6 commit 8a9a5c3

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

databricks_cli/jobs/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def __init__(self, api_client):
3030
def create_job(self, json, headers=None):
3131
return self.client.client.perform_query('POST', '/jobs/create', data=json, headers=headers)
3232

33-
def list_jobs(self, headers=None):
34-
resp = self.client.list_jobs(headers=headers)
33+
def list_jobs(self, job_type=None, headers=None):
34+
resp = self.client.list_jobs(job_type, headers=headers)
3535
if 'jobs' not in resp:
3636
resp['jobs'] = []
3737
return resp

databricks_cli/jobs/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ def _jobs_to_table(jobs_json):
9595
@click.command(context_settings=CONTEXT_SETTINGS,
9696
short_help='Lists the jobs in the Databricks Job Service.')
9797
@click.option('--output', default=None, help=OutputClickType.help, type=OutputClickType())
98+
@click.option('--type', 'job_type', default=None, help='The type of job to list', type=str)
9899
@debug_option
99100
@profile_option
100101
@eat_exceptions
101102
@provide_api_client
102-
def list_cli(api_client, output):
103+
def list_cli(api_client, output, job_type):
103104
"""
104105
Lists the jobs in the Databricks Job Service.
105106
@@ -114,7 +115,7 @@ def list_cli(api_client, output):
114115
In table mode, the jobs are sorted by their name.
115116
"""
116117
jobs_api = JobsApi(api_client)
117-
jobs_json = jobs_api.list_jobs()
118+
jobs_json = jobs_api.list_jobs(job_type)
118119
if OutputClickType.is_json(output):
119120
click.echo(pretty_format(jobs_json))
120121
else:

databricks_cli/sdk/service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ def get_job(self, job_id, headers=None):
138138
_data['job_id'] = job_id
139139
return self.client.perform_query('GET', '/jobs/get', data=_data, headers=headers)
140140

141-
def list_jobs(self, headers=None):
141+
def list_jobs(self, job_type=None, headers=None):
142142
_data = {}
143143

144+
if job_type is not None:
145+
_data['job_type'] = job_type
146+
144147
return self.client.perform_query('GET', '/jobs/list', data=_data, headers=headers)
145148

146149
def run_now(self, job_id=None, jar_params=None, notebook_params=None, python_params=None,

tests/jobs/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ def test_list_jobs_output_json(jobs_api_mock):
123123
assert echo_mock.call_args[0][0] == pretty_format(LIST_RETURN)
124124

125125

126+
@provide_conf
127+
def test_list_jobs_type_pipeline(jobs_api_mock):
128+
with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
129+
jobs_api_mock.list_jobs.return_value = LIST_RETURN
130+
runner = CliRunner()
131+
runner.invoke(cli.list_cli, ['--type', 'PIPELINE'])
132+
assert jobs_api_mock.list_jobs.call_args[0][0] == 'PIPELINE'
133+
rows = [(2, 'a'), (1, 'b'), (30, 'C')]
134+
assert echo_mock.call_args[0][0] == \
135+
tabulate(rows, tablefmt='plain', disable_numparse=True)
136+
137+
126138
RUN_NOW_RETURN = {
127139
"number_in_job": 1,
128140
"run_id": 1

0 commit comments

Comments
 (0)