<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic how to get schedule information about a job in databricks? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112393#M44199</link>
    <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;I was reading the Databricks API documentation and I want to get information about one job if this is schedule with the status PAUSED or UNPAUSED. I was watching that there is this api call:&amp;nbsp;&lt;A href="https://docs.databricks.com/api/workspace/jobs/get" target="_blank"&gt;https://docs.databricks.com/api/workspace/jobs/get&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tried to make the code for it and testing it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def _get_single_job_api_call(self):
        """Get single job information through Databricks API call"""

        headers = {
            'Authorization': f'Bearer {self.access_token}',
            'Content-Type': 'application/json'
        }

        try:
            response = requests.get(
                url = f'{self.workspace_host}/api/2.2/jobs/get', 
                json = {'job_id': self.job_id},
                headers = headers
            )
            response.raise_for_status()  # Raises HTTPError for bad responses (4xx and 5xx)
            return response.json()
        except requests.exceptions.Timeout:
            logger.error("Request timed out.")
        except requests.exceptions.ConnectionError:
            logger.error("Failed to connect to the server.")
        except requests.exceptions.HTTPError as e:
            logger.error(f"HTTP error occurred: {e}")
        except requests.exceptions.RequestException as e:
            logger.error(f"Request failed: {e}")
        except Exception as e:
            logger.error(f"Unexpected error: {e}")
        
        return None


    def is_job_scheduled(self):
        get_job_status = self._get_single_job_api_call()
        schedule_job_status = get_job_status['settings']['schedule']['pause_status']
        
        if not get_job_status:
            logger.error("Failed to retrieve job status.")
            return True  # Safeguard by assuming it's scheduled
        
        try:
            schedule_job_status = get_job_status['settings']['schedule']['pause_status']
            return schedule_job_status != 'UNPAUSED'  # True if PAUSED or any other value, False only if explicitly UNPAUSED
        except KeyError:
            logger.error("Job schedule information is missing. Assuming job is scheduled for safety.")
            return True  # Safeguard by assuming it's scheduled&lt;/LI-CODE&gt;&lt;P data-unlink="true"&gt;But, I'm receiving errors like:&lt;STRONG&gt;&amp;nbsp;HTTP error occurred: 403 Client Error: Forbidden for url: &amp;lt;workspace_host&amp;gt;/api/2.2/jobs/get&lt;/STRONG&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;with this error message inside:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{"error_code":401,"message":"Credential was not sent or was of an unsupported type for this API."}&lt;/PRE&gt;&lt;P&gt;how can I solve it, I'm making the api call wrong?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Mar 2025 16:21:30 GMT</pubDate>
    <dc:creator>jeremy98</dc:creator>
    <dc:date>2025-03-12T16:21:30Z</dc:date>
    <item>
      <title>how to get schedule information about a job in databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112393#M44199</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;I was reading the Databricks API documentation and I want to get information about one job if this is schedule with the status PAUSED or UNPAUSED. I was watching that there is this api call:&amp;nbsp;&lt;A href="https://docs.databricks.com/api/workspace/jobs/get" target="_blank"&gt;https://docs.databricks.com/api/workspace/jobs/get&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tried to make the code for it and testing it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def _get_single_job_api_call(self):
        """Get single job information through Databricks API call"""

        headers = {
            'Authorization': f'Bearer {self.access_token}',
            'Content-Type': 'application/json'
        }

        try:
            response = requests.get(
                url = f'{self.workspace_host}/api/2.2/jobs/get', 
                json = {'job_id': self.job_id},
                headers = headers
            )
            response.raise_for_status()  # Raises HTTPError for bad responses (4xx and 5xx)
            return response.json()
        except requests.exceptions.Timeout:
            logger.error("Request timed out.")
        except requests.exceptions.ConnectionError:
            logger.error("Failed to connect to the server.")
        except requests.exceptions.HTTPError as e:
            logger.error(f"HTTP error occurred: {e}")
        except requests.exceptions.RequestException as e:
            logger.error(f"Request failed: {e}")
        except Exception as e:
            logger.error(f"Unexpected error: {e}")
        
        return None


    def is_job_scheduled(self):
        get_job_status = self._get_single_job_api_call()
        schedule_job_status = get_job_status['settings']['schedule']['pause_status']
        
        if not get_job_status:
            logger.error("Failed to retrieve job status.")
            return True  # Safeguard by assuming it's scheduled
        
        try:
            schedule_job_status = get_job_status['settings']['schedule']['pause_status']
            return schedule_job_status != 'UNPAUSED'  # True if PAUSED or any other value, False only if explicitly UNPAUSED
        except KeyError:
            logger.error("Job schedule information is missing. Assuming job is scheduled for safety.")
            return True  # Safeguard by assuming it's scheduled&lt;/LI-CODE&gt;&lt;P data-unlink="true"&gt;But, I'm receiving errors like:&lt;STRONG&gt;&amp;nbsp;HTTP error occurred: 403 Client Error: Forbidden for url: &amp;lt;workspace_host&amp;gt;/api/2.2/jobs/get&lt;/STRONG&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;with this error message inside:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{"error_code":401,"message":"Credential was not sent or was of an unsupported type for this API."}&lt;/PRE&gt;&lt;P&gt;how can I solve it, I'm making the api call wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2025 16:21:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112393#M44199</guid>
      <dc:creator>jeremy98</dc:creator>
      <dc:date>2025-03-12T16:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to get schedule information about a job in databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112397#M44200</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/133094"&gt;@jeremy98&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like the access token is incorrect or not valid. Can you please verify the following?&lt;/P&gt;&lt;P&gt;1. Validate your access token - if you get 403 forbidden error, your access token is invalid.&lt;/P&gt;&lt;P&gt;curl -X GET "https://&amp;lt;workspace_host&amp;gt;/api/2.2/jobs/get" \&lt;BR /&gt;-H "Authorization: Bearer &amp;lt;your_token&amp;gt;" \&lt;BR /&gt;-H "Content-Type: application/json" \&lt;BR /&gt;-d '{"job_id": &amp;lt;your_job_id&amp;gt;}'&lt;/P&gt;&lt;P&gt;2. Validate your workspace host url&amp;nbsp;&lt;/P&gt;&lt;P&gt;print(self.workspace_host)&lt;/P&gt;&lt;P&gt;It should be in this format and ensure no trailing slash at the end -&amp;nbsp;&lt;A href="https://community.databricks.com/" target="_blank"&gt;https://&amp;lt;databricks-instance&amp;gt;.cloud.databricks.com&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2025 17:01:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112397#M44200</guid>
      <dc:creator>KaranamS</dc:creator>
      <dc:date>2025-03-12T17:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to get schedule information about a job in databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112456#M44216</link>
      <description>&lt;P&gt;Yes, thanks, the problem was the access_token that is not set in the other environment&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 09:25:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-get-schedule-information-about-a-job-in-databricks/m-p/112456#M44216</guid>
      <dc:creator>jeremy98</dc:creator>
      <dc:date>2025-03-13T09:25:48Z</dc:date>
    </item>
  </channel>
</rss>

