Skip to content

Commit

Permalink
avoid unique error messages (superdesk#658)
Browse files Browse the repository at this point in the history
* avoid unique error messages

so it won't create a new error on sentry every time
but can aggregate those together.

* add user id to notification
  • Loading branch information
petrjasek authored Nov 20, 2023
1 parent 7516aef commit 1c1ebe1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
9 changes: 4 additions & 5 deletions newsroom/company_expiry_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from superdesk import get_resource_service
from superdesk.utc import utcnow
from superdesk.celery_task_utils import get_lock_id
from superdesk.lock import lock, unlock, remove_locks
from superdesk.lock import lock, unlock

from newsroom.celery_app import celery
from newsroom.settings import get_settings_collection, GENERAL_SETTINGS_LOOKUP
Expand All @@ -31,16 +31,15 @@ def send_alerts(self):

lock_name = get_lock_id("newsroom", "company_expiry")
if not lock(lock_name, expire=610):
logger.error("{} Job already running".format(self.log_msg))
logger.error("Company expiry alert task already running")
return

try:
self.worker()
except Exception as e:
logger.exception(e)

unlock(lock_name)
remove_locks()
finally:
unlock(lock_name)

logger.info("{} Completed sending alerts.".format(self.log_msg))

Expand Down
9 changes: 4 additions & 5 deletions newsroom/monitoring/email_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from superdesk import get_resource_service, Command
from superdesk.utc import utcnow, utc_to_local, local_to_utc
from superdesk.celery_task_utils import get_lock_id
from superdesk.lock import lock, unlock, remove_locks
from superdesk.lock import lock, unlock

from newsroom.celery_app import celery
from newsroom.settings import get_settings_collection, GENERAL_SETTINGS_LOOKUP
Expand Down Expand Up @@ -48,7 +48,7 @@ def run(self, immediate=False):
"monitoring_{0}".format("scheduled" if not immediate else "immediate"),
)
if not lock(lock_name, expire=610):
logger.error("{} Job already running".format(self.log_msg))
logger.error("Monitoring email alerts task already running")
return

try:
Expand All @@ -64,9 +64,8 @@ def run(self, immediate=False):
self.scheduled_worker(now_to_minute)
except Exception as e:
logger.exception(e)

unlock(lock_name)
remove_locks()
finally:
unlock(lock_name)

logger.info("{} Completed sending Monitoring Scheduled Alerts.".format(self.log_msg))

Expand Down
16 changes: 8 additions & 8 deletions newsroom/notifications/send_scheduled_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from superdesk import get_resource_service, Command
from superdesk.utc import utcnow, utc_to_local
from superdesk.celery_task_utils import get_lock_id
from superdesk.lock import lock, unlock, remove_locks
from superdesk.lock import lock, unlock

from newsroom.types import User, NotificationSchedule, Company, NotificationQueue, NotificationQueueTopic, Topic
from newsroom.utils import get_user_dict, get_company_dict
Expand All @@ -32,13 +32,13 @@ def run(self, force: bool = False):

lock_name = get_lock_id("newsroom", "send_scheduled_notifications")
if not lock(lock_name, expire=610):
logger.error(f"{self.log_msg} Job already running")
logger.error("Send scheduled notifications task already running")
return

self.run_schedules(force)

unlock(lock_name)
remove_locks()
try:
self.run_schedules(force)
finally:
unlock(lock_name)

logger.info(f"{self.log_msg} Completed sending scheduled notifications")

Expand All @@ -51,8 +51,8 @@ def run_schedules(self, force: bool):

schedules: List[NotificationQueue] = get_resource_service("notification_queue").get(req=None, lookup={})
except Exception as e:
logger.error(f"{self.log_msg} Failed to retrieve data to run schedules")
logger.exception(e)
logger.error("Failed to retrieve data to run schedules")
return

for schedule in schedules:
Expand All @@ -76,7 +76,7 @@ def run_schedules(self, force: bool):
self.process_schedule(schedule, user, company, now_utc, user_topic_map.get(user["_id"]) or {}, force)
except Exception as e:
logger.exception(e)
logger.error(f"{self.log_msg} Failed to run schedule for user {user_id}")
logger.error("Failed to run schedule for user %s", user_id)

def process_schedule(
self,
Expand Down

0 comments on commit 1c1ebe1

Please sign in to comment.