Created
July 11, 2021 18:25
-
-
Save kuharan/2158a6e8224632fb6098b35f9b7862f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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