Esempio n. 1
0
    def notify_content_update(self, content: Content):

        if content.get_last_action().id not \
                in self.config.EMAIL_NOTIFICATION_NOTIFIED_EVENTS:
            logger.info(
                self,
                'Skip email notification for update of content {}'
                'by user {} (the action is {})'.format(
                    content.content_id,
                    # below: 0 means "no user"
                    self._user.user_id if self._user else 0,
                    content.get_last_action().id
                )
            )
            return

        logger.info(self,
                    'About to email-notify update'
                    'of content {} by user {}'.format(
                        content.content_id,
                        # Below: 0 means "no user"
                        self._user.user_id if self._user else 0
                    )
        )

        if content.type not \
                in self.config.EMAIL_NOTIFICATION_NOTIFIED_CONTENTS:
            logger.info(
                self,
                'Skip email notification for update of content {}'
                'by user {} (the content type is {})'.format(
                    content.type,
                    # below: 0 means "no user"
                    self._user.user_id if self._user else 0,
                    content.get_last_action().id
                )
            )
            return

        logger.info(self,
                    'About to email-notify update'
                    'of content {} by user {}'.format(
                        content.content_id,
                        # Below: 0 means "no user"
                        self._user.user_id if self._user else 0
                    )
        )

        ####
        #
        # INFO - D.A. - 2014-11-05 - Emails are sent through asynchronous jobs.
        # For that reason, we do not give SQLAlchemy objects but ids only
        # (SQLA objects are related to a given thread/session)
        #
        try:
            if self.config.EMAIL_NOTIFICATION_PROCESSING_MODE.lower() == self.config.CST.ASYNC.lower():
                logger.info(self, 'Sending email in ASYNC mode')
                # TODO - D.A - 2014-11-06
                # This feature must be implemented in order to be able to scale to large communities
                raise NotImplementedError('Sending emails through ASYNC mode is not working yet')
            else:
                logger.info(self, 'Sending email in SYNC mode')
                EmailManager(
                    self._smtp_config,
                    self.config,
                    self.session,
                ).notify_content_update(self._user.user_id, content.content_id)
        except Exception as e:
            # TODO - G.M - 2018-08-27 - Do Better catching for exception here
            logger.error(self, 'Exception catched during email notification: {}'.format(e.__str__()))
            logger.exception(self, e)
Esempio n. 2
0
    def notify_content_update(self, content: Content):

        if content.get_last_action(
        ).id not in self.config.EMAIL__NOTIFICATION__NOTIFIED_EVENTS:
            logger.info(
                self,
                "Skip email notification for update of content {}"
                "by user {} (the action is {})".format(
                    content.content_id,
                    # below: 0 means "no user"
                    self._user.user_id if self._user else 0,
                    content.get_last_action().id,
                ),
            )
            return

        logger.info(
            self,
            "About to email-notify update"
            "of content {} by user {}".format(
                content.content_id,
                # Below: 0 means "no user"
                self._user.user_id if self._user else 0,
            ),
        )

        if content.type not in self.config.EMAIL__NOTIFICATION__NOTIFIED_CONTENTS:
            logger.info(
                self,
                "Skip email notification for update of content {}"
                "by user {} (the content type is {})".format(
                    content.type,
                    # below: 0 means "no user"
                    self._user.user_id if self._user else 0,
                    content.get_last_action().id,
                ),
            )
            return

        logger.info(
            self,
            "About to email-notify update"
            "of content {} by user {}".format(
                content.content_id,
                # Below: 0 means "no user"
                self._user.user_id if self._user else 0,
            ),
        )

        ####
        #
        # INFO - D.A. - 2014-11-05 - Emails are sent through asynchronous jobs.
        # For that reason, we do not give SQLAlchemy objects but ids only
        # (SQLA objects are related to a given thread/session)
        #
        try:
            if (self.config.EMAIL__NOTIFICATION__PROCESSING_MODE.lower() ==
                    self.config.CST.ASYNC.lower()):
                logger.info(self, "Sending email in ASYNC mode")
                # TODO - D.A - 2014-11-06
                # This feature must be implemented in order to be able to scale to large communities
                raise NotImplementedError(
                    "Sending emails through ASYNC mode is not working yet")
            else:
                logger.info(self, "Sending email in SYNC mode")
                EmailManager(self._smtp_config, self.config,
                             self.session).notify_content_update(
                                 self._user.user_id, content.content_id)
        except Exception:
            logger.exception(self,
                             "Exception catched during email notification")