Ejemplo n.º 1
0
 def handle(self, *args, **options):
     logger.info("Sherlock Notify Service: Notifying backfill outcome...")
     if BackfillNotificationRecord.objects.count() == 0:
         logger.info(
             "Sherlock Notify Service: Nothing to report via email.")
         return
     notify = notify_client_factory()
     email_writer = BackfillNotificationWriter()
     sent_confirmation = True
     while BackfillNotificationRecord.objects.count(
     ) != 0 & sent_confirmation:
         backfills_to_email = BackfillNotificationRecord.objects.all(
         )[:MAX_COUNT_OF_ROWS_PER_EMAIL]
         backfilled_records = [
             backfill.record for backfill in backfills_to_email
         ]
         if backfilled_records:
             backfill_notification = email_writer.prepare_new_email(
                 backfilled_records)
             logger.debug(
                 f"Sherlock Notify Service: Composed email notification payload `{backfill_notification}`."
             )
             # send email
             notification_outcome = notify.email(backfill_notification)
             logger.debug(
                 f"Sherlock Notify Service: Email notification service replied with `{notification_outcome}`."
             )
             if notification_outcome[
                     'response'].status_code == SUCCESS_STATUS:
                 logger.debug(
                     "Sherlock Notify Service: Removing notified records from helper table."
                 )
                 for record in backfills_to_email:
                     record.delete()
             else:
                 sent_confirmation = False
                 logger.debug(
                     "Sherlock Notify Service: Email notification service failed."
                 )
Ejemplo n.º 2
0
    def __init__(
        self,
        report_maintainer: BackfillReportMaintainer,
        backfill_tool: BackfillTool,
        secretary_tool: SecretaryTool,
        notify_client: taskcluster.Notify,
        max_runtime: timedelta = None,
        email_writer: EmailWriter = None,
    ):
        self.report_maintainer = report_maintainer
        self.backfill_tool = backfill_tool
        self.secretary = secretary_tool
        self._notify = notify_client
        self._max_runtime = self.DEFAULT_MAX_RUNTIME if max_runtime is None else max_runtime
        self._email_writer = email_writer or BackfillNotificationWriter()

        self._wake_up_time = datetime.now()
        self.backfilled_records = []  # useful for reporting backfill outcome
Ejemplo n.º 3
0
 def email_writer_mock():
     return MagicMock(spec=BackfillNotificationWriter())