03-06-2022 09:27 PM
How to get the last databricks job run time? I have a requirement where i need to pass last job runtime as an argument in SQL and this SQL get the records from snowflake database based on this timestamp.
03-07-2022 02:39 AM
03-07-2022 02:39 AM
You can get last job run time using Jobs API: https://docs.databricks.com/dev-tools/api/latest/jobs.html#operation/JobsRunsList
03-07-2022 06:53 AM
Thank you very much for your response Hubert. How can we call these api in databricks code? it would be really help if you have any sample code.
03-07-2022 07:21 PM
@Srinivas Gannavaram : Sample python pseudocode for jobs API. Hope this helps you to build your Logic
import requests
import json
databricks_instance ="<databricks-instances>"
url_list = f"{databricks_instance}/api/2.1/jobs/runs/get?run_id=<Your Job RunID>"
headers = {
'Authorization': 'Bearer <databricks-access-token>',
'Content-Type': 'application/json'
}
response = requests.request("GET", url_list, headers=headers).json()
print(response)
print(response['job_id'])
print(response['start_time'])
print(response['end_time'])
03-07-2022 08:05 PM
Thank you so much. I will test it.
03-08-2022 01:20 PM
@Srinivas Gannavaram - Please let us know how it goes!
04-22-2022 07:08 AM
Hey there @Srinivas Gannavaram
Hope you are well. Just wanted to see if you were able to find an answer to your question and would you like to mark an answer as best? It would be really helpful for the other members.
Cheers!
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group