Fixes and added tests for the security notification worker
Fixes #1301 - Ensures that the worker uses pagination properly - Ensures that the worker handles failure as expected - Moves marking the notification as read to after the worker processes it - Increases the number of layers requested to 100
This commit is contained in:
parent
e8a511d526
commit
aa5587c93c
4 changed files with 75 additions and 15 deletions
|
@ -11,6 +11,7 @@ from util.secscan.notifier import process_notification_data
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
_EXTENDED_SECONDS = 600
|
||||
_LAYER_LIMIT = 100 # The number of layers to request on each page.
|
||||
|
||||
class SecurityNotificationWorker(QueueWorker):
|
||||
def process_queue_item(self, data):
|
||||
|
@ -18,14 +19,16 @@ class SecurityNotificationWorker(QueueWorker):
|
|||
current_page = data.get('page', None)
|
||||
|
||||
while True:
|
||||
(response_data, should_retry) = secscan_api.get_notification(notification_name)
|
||||
(response_data, should_retry) = secscan_api.get_notification(notification_name,
|
||||
layer_limit=_LAYER_LIMIT,
|
||||
page=current_page)
|
||||
if response_data is None:
|
||||
if should_retry:
|
||||
raise JobException()
|
||||
else:
|
||||
# Return to mark the job as "complete", as we'll never be able to finish it.
|
||||
logger.error('Failed to handle security notification %s', notification_name)
|
||||
return
|
||||
return False
|
||||
|
||||
notification_data = response_data['Notification']
|
||||
if not process_notification_data(notification_data):
|
||||
|
@ -33,7 +36,13 @@ class SecurityNotificationWorker(QueueWorker):
|
|||
|
||||
# Check for a next page of results. If none, we're done.
|
||||
if 'NextPage' not in notification_data:
|
||||
return
|
||||
# Mark the notification as read and processed.
|
||||
if not secscan_api.mark_notification_read(notification_name):
|
||||
# Return to mark the job as "complete", as we'll never be able to finish it.
|
||||
logger.error('Failed to mark notification %s as read', notification_name)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
# Otherwise, save the next page token into the queue item (so we can pick up from here if
|
||||
# something goes wrong in the next loop iteration), and continue.
|
||||
|
|
Reference in a new issue