Skip to content

Instantly share code, notes, and snippets.

@kuharan
Created July 11, 2021 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuharan/2158a6e8224632fb6098b35f9b7862f2 to your computer and use it in GitHub Desktop.
Save kuharan/2158a6e8224632fb6098b35f9b7862f2 to your computer and use it in GitHub Desktop.
def find_last_success_run(access_token, session, all_backup_specification):
url = "https://xxxx.com:7116/idb/sessions/filter/"
headers = {
'Authorization': 'Bearer {}'.format(access_token),
'Content-Type': 'application/json'
}
all_completed_runs = []
sessions_not_found = []
for backup_specification in all_backup_specification:
payload = json.dumps({
"filter": {
"sessionType": [0],
"datalist": backup_specification['specName'],
"status" : [2]
}
})
response = json.loads(session.post(url, headers=headers, data=payload).text)
#sort the list of dictionary in desc based on endtime to get the latest completed run
try:
last_completed_run = sorted(response['items'], key=lambda k: k['endTime'], reverse=True)[0]
except:
sessions_not_found.append(backup_specification['specName'])
all_completed_runs.append(last_completed_run)
return all_completed_runs, sessions_not_found
all_completed_runs, sessions_not_found = find_last_success_run(access_token, session, all_backup_specification)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment