Пример #1
0
    def send_message_to_all_contributors(project_id: int,
                                         message_dto: MessageDTO):
        """  Sends supplied message to all contributors on specified project.  Message all contributors can take
             over a minute to run, so this method is expected to be called on its own thread """

        app = create_app(
        )  # Because message-all run on background thread it needs it's own app context

        with app.app_context():
            contributors = Message.get_all_contributors(project_id)

            project_link = MessageService.get_project_link(project_id)

            message_dto.message = f'{project_link}<br/><br/>' + message_dto.message  # Append project link to end of message

            msg_count = 0
            for contributor in contributors:
                message = Message.from_dto(contributor[0], message_dto)
                message.save()
                user = UserService.get_user_by_id(contributor[0])
                SMTPService.send_email_alert(user.email_address, user.username)
                msg_count += 1
                if msg_count == 10:
                    time.sleep(
                        0.5
                    )  # Sleep for 0.5 seconds to avoid hitting AWS rate limits every 10 messages
                    msg_count = 0
    def send_message_to_all_contributors(project_id: int, message_dto: MessageDTO):
        """ Sends supplied message to all contributors on specified project """
        contributors = Message.get_all_contributors(project_id)

        for contributor in contributors:
            message = Message.from_dto(contributor[0], message_dto)
            message.save()
            user = UserService.get_user_by_id(contributor[0])
            SMTPService.send_email_alert(user.email_address, user.username)
Пример #3
0
    def send_message_to_all_contributors(project_id: int, message_dto: MessageDTO):
        """ Sends supplied message to all contributors on specified project """
        contributors = Message.get_all_contributors(project_id)

        project_link = MessageService.get_project_link(project_id)

        message_dto.message = f'{project_link}<br/><br/>' + message_dto.message  # Append project link to end of message

        for contributor in contributors:
            message = Message.from_dto(contributor[0], message_dto)
            message.save()
            user = UserService.get_user_by_id(contributor[0])
            SMTPService.send_email_alert(user.email_address, user.username)
    def send_message_to_all_contributors(project_id: int,
                                         message_dto: MessageDTO):
        """ Sends supplied message to all contributors on specified project """
        contributors = Message.get_all_contributors(project_id)

        project_link = MessageService.get_project_link(project_id)

        message_dto.message = f'{project_link}<br/><br/>' + message_dto.message  # Append project link to end of message

        msg_count = 0
        for contributor in contributors:
            message = Message.from_dto(contributor[0], message_dto)
            message.save()
            user = UserService.get_user_by_id(contributor[0])
            SMTPService.send_email_alert(user.email_address, user.username)
            msg_count += 1
            if msg_count == 5:
                time.sleep(
                    0.5
                )  # Sleep for 0.5 seconds to avoid hitting AWS rate limits every 5 messages
                msg_count = 0