send notification error handling

This commit is contained in:
Setyo Nugroho 2022-09-20 12:45:09 +07:00
parent f5be3a8c3c
commit 235d75fd30

View file

@ -1,3 +1,4 @@
import logging
import re import re
import math import math
@ -15,6 +16,8 @@ from core.component.labels import LABEL_INSTANCES, LABEL_IMAGES, LABEL_SNAPSHOTS
LABEL_VOLUMES LABEL_VOLUMES
from core.utils.model_utils import BaseModel, TimestampMixin, PriceMixin, InvoiceComponentMixin from core.utils.model_utils import BaseModel, TimestampMixin, PriceMixin, InvoiceComponentMixin
LOG = logging.getLogger("yuyu")
# region Dynamic Setting # region Dynamic Setting
class DynamicSetting(BaseModel): class DynamicSetting(BaseModel):
@ -271,7 +274,7 @@ class Notification(BaseModel, TimestampMixin):
def send(self): def send(self):
from core.utils.dynamic_setting import get_dynamic_setting, EMAIL_ADMIN from core.utils.dynamic_setting import get_dynamic_setting, EMAIL_ADMIN
try:
def textify(html): def textify(html):
# Remove html tags and continuous whitespaces # Remove html tags and continuous whitespaces
text_only = re.sub('[ \t]+', ' ', strip_tags(html)) text_only = re.sub('[ \t]+', ' ', strip_tags(html))
@ -289,6 +292,9 @@ class Notification(BaseModel, TimestampMixin):
recipient_list=recipient, recipient_list=recipient,
html_message=self.content, html_message=self.content,
) )
self.sent_status = True self.sent_status = True
self.save() self.save()
except Exception as e:
LOG.exception('Error sending notification')
self.sent_status = False
self.save()