Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to update individual settings when using JobsService.update_job method #606

Open
georgikoemdzhiev opened this issue Feb 23, 2023 · 3 comments

Comments

@georgikoemdzhiev
Copy link

georgikoemdzhiev commented Feb 23, 2023

Hello,

Is is possible to add support for updating individual settings with the update_job method:

def update_job(
self, job_id, new_settings=None, fields_to_remove=None, headers=None, version=None
):
_data = {}
if job_id is not None:
_data['job_id'] = job_id
if new_settings is not None:
_data['new_settings'] = new_settings
if not isinstance(new_settings, dict):
raise TypeError('Expected databricks.JobSettings() or dict for field new_settings')
if fields_to_remove is not None:
_data['fields_to_remove'] = fields_to_remove
return self.client.perform_query(
'POST', '/jobs/update', data=_data, headers=headers, version=version
)

Currently, when I would like to update just the schedule.pause_status of a job using this code:

from databricks_cli.sdk.api_client import ApiClient
from databricks_cli.sdk.service import JobsService

api_client = ApiClient(host=databricks_host, token=databricks_token)
jobs_service = JobsService(api_client)

reset_dict = {'schedule': {'pause_status': 'PAUSED'}}
jobs_service.update_job(job_id='728701863935760', new_settings=reset_dict)

I am getting this error stating that I need to provide the other 2 "required" parameters of the settings block:

Traceback (most recent call last):
  File "/home/vsts/work/1/s/main.py", line 34, in <module>
    dr.pause_all_jobs(args.databricks_host, args.databricks_token)
  File "/home/vsts/work/1/s/main.py", line 26, in pause_all_jobs
    jobs_service.update_job(job_id='728701863935760',
  File "/home/vsts/.local/lib/python3.10/site-packages/databricks_cli/sdk/service.py", line 269, in update_job
    return self.client.perform_query(
  File "/home/vsts/.local/lib/python3.10/site-packages/databricks_cli/sdk/api_client.py", line 174, in perform_query
    raise requests.exceptions.HTTPError(message, response=e.response)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://mydatabricks.cloud.databricks.com/api/2.0/jobs/update
 Response from server: 
 { 'error_code': 'INVALID_PARAMETER_VALUE',
  'message': 'Missing required fields: '
             'new_settings.schedule.quartz_cron_expression, '
             'new_settings.schedule.timezone_id'}

I used databricks-cli==0.17.4 version when I got the above error

@mroy-seedbox
Copy link

mroy-seedbox commented Feb 23, 2023

Just read the current job definition from the API using get_job(), change the fields you want to change, and post it back. 🤷‍♂️

@georgikoemdzhiev
Copy link
Author

Just read the current job definition from the API using get_job(), change the fields you want to change, and post it back. 🤷‍♂️

Thank you for your suggestion. I guess that would work as well. However, I am hoping that Databricks can make that process even easier.

@georgikoemdzhiev
Copy link
Author

Just read the current job definition from the API using get_job(), change the fields you want to change, and post it back. 🤷‍♂️

I tried your suggestion but the approach does not seem to work for me. I tried to change the job's scheduler. I opened another issue to track that here #616

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants