From 8481b10db07e11fad15cab32a84437f380395857 Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 12 Mar 2022 22:47:12 +0530 Subject: [PATCH 1/4] Log to sentry when publishing takes too long --- .../contentcuration/utils/publish.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index 4c8a54ad73..65e972164d 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -54,6 +54,27 @@ THUMBNAIL_DIMENSION = 128 MIN_SCHEMA_VERSION = "1" BLOCKING_TASK_TYPES = ["duplicate-nodes", "move-nodes", "sync-channel"] +PUBLISHING_UPDATE_THRESHOLD = 3600 + + +class SlowPublishError(Exception): + """ + Used to track slow Publishing operations. We don't raise this error, + just feed it to Sentry for reporting. + """ + + def __init__(self, time, channel_id): + + self.time = time + self.channel_id = channel_id + message = ( + "publishing the channel with channel_id {} took {} seconds to complete, exceeding {} second threshold." + ) + self.message = message.format( + self.channel_id, self.time, PUBLISHING_UPDATE_THRESHOLD + ) + + super(SlowPublishError, self).__init__(self.message) def send_emails(channel, user_id, version_notes=''): @@ -766,7 +787,7 @@ def publish_channel( """ channel = ccmodels.Channel.objects.get(pk=channel_id) kolibri_temp_db = None - + start = time.time() try: set_channel_icon_encoding(channel) wait_for_async_tasks(channel) @@ -799,4 +820,12 @@ def publish_channel( os.remove(kolibri_temp_db) channel.main_tree.publishing = False channel.main_tree.save() + + elapsed = time.time() - start + + if elapsed > PUBLISHING_UPDATE_THRESHOLD: + try: + raise SlowPublishError(elapsed, channel_id) + except SlowPublishError as e: + report_exception(e) return channel From 690db9d51c3caa772bfa7a3a6e2b5c7e5eb123a6 Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Wed, 23 Mar 2022 20:23:37 +0530 Subject: [PATCH 2/4] Update publish.py Simplified exception --- contentcuration/contentcuration/utils/publish.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index 65e972164d..9f6da2a4d1 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -824,8 +824,5 @@ def publish_channel( elapsed = time.time() - start if elapsed > PUBLISHING_UPDATE_THRESHOLD: - try: - raise SlowPublishError(elapsed, channel_id) - except SlowPublishError as e: - report_exception(e) + report_exception(SlowPublishError(elapsed, channel_id)) return channel From 64f8bc2e2da5d5cf34a6436e995db859ae538934 Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 26 Mar 2022 11:21:17 +0530 Subject: [PATCH 3/4] Comment on raising exception --- contentcuration/contentcuration/utils/publish.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index 9f6da2a4d1..bb2a3d2fb5 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -824,5 +824,10 @@ def publish_channel( elapsed = time.time() - start if elapsed > PUBLISHING_UPDATE_THRESHOLD: - report_exception(SlowPublishError(elapsed, channel_id)) + # we raise the exception so that sentry has the stack trace when it tries to log log it + # we need to raise it to get Python to fill out the stack trace. + try: + raise SlowPublishError(elapsed, channel_id) + except SlowPublishError as e: + report_exception(e) return channel From 2e58dfaccf04c822b8b9b8d2d8e50faf43ba0e31 Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 26 Mar 2022 11:22:46 +0530 Subject: [PATCH 4/4] Fixed typo --- contentcuration/contentcuration/utils/publish.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index bb2a3d2fb5..e55e8bd745 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -824,7 +824,7 @@ def publish_channel( elapsed = time.time() - start if elapsed > PUBLISHING_UPDATE_THRESHOLD: - # we raise the exception so that sentry has the stack trace when it tries to log log it + # we raise the exception so that sentry has the stack trace when it tries to log it # we need to raise it to get Python to fill out the stack trace. try: raise SlowPublishError(elapsed, channel_id)