|
59 | 59 | import json
|
60 | 60 | import traceback
|
61 | 61 | import re
|
62 |
| -from requests import HTTPError |
| 62 | +from requests import RequestException |
63 | 63 | from blackduck import Client
|
64 | 64 | from ast import literal_eval
|
65 | 65 |
|
@@ -120,24 +120,32 @@ def main():
|
120 | 120 |
|
121 | 121 | user = get_user(hub_client, user_name)
|
122 | 122 | if user:
|
123 |
| - number_of_seen = 0 |
124 |
| - for notification in read_notifications( |
125 |
| - hub_client, |
126 |
| - notification_filters, |
127 |
| - user, |
128 |
| - vuln_source=vuln_source): |
129 |
| - user_id = re.split("/", user['_meta']['href'])[-1] |
130 |
| - res = update_user_notification(hub_client, user_id, notification) |
131 |
| - number_of_seen += 1 |
132 |
| - content = literal_eval(res.content.decode("UTF-8")) |
133 |
| - logging.info(f"Notification state is set to SEEN for {content['type']}") |
134 |
| - logging.info(f"Finished. Number of Notifications which are set to SEEN is {number_of_seen}") |
| 123 | + set_to_seen = 0 |
| 124 | + failed = 0 |
| 125 | + while True: |
| 126 | + try: |
| 127 | + for notification in read_notifications( |
| 128 | + hub_client, |
| 129 | + notification_filters, |
| 130 | + user, |
| 131 | + vuln_source=vuln_source): |
| 132 | + user_id = re.split("/", user['_meta']['href'])[-1] |
| 133 | + res = update_user_notification(hub_client, user_id, notification) |
| 134 | + set_to_seen += 1 |
| 135 | + content = literal_eval(res.content.decode("UTF-8")) |
| 136 | + logging.info(f"Notification state is set to SEEN for {content['type']}") |
| 137 | + except RequestException as err: |
| 138 | + failed += 1 |
| 139 | + logging.error(f"Failed to read or update notification and the reason is {str(err)}") |
| 140 | + continue |
| 141 | + logging.info(f"=== Updating Notifications Finished ===") |
| 142 | + logging.info(f"{set_to_seen} Notifications are set to SEEN.") |
| 143 | + logging.info(f"{failed} Notifications failed to read or update the state.") |
| 144 | + break |
135 | 145 | else:
|
136 | 146 | logging.error(f"User not found for {user_name}")
|
137 |
| - except HTTPError as err: |
138 |
| - hub_client.http_error_handler(err) |
139 | 147 | except Exception as err:
|
140 |
| - logging.error(f"Failed to perform the task. See the stack trace") |
| 148 | + logging.error(f"Failed to perform the task with exception {str(err)}. See also the stack trace") |
141 | 149 | traceback.print_exc()
|
142 | 150 |
|
143 | 151 | if __name__ == '__main__':
|
|
0 commit comments