Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=''):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -799,4 +820,14 @@ 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:
# 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)
except SlowPublishError as e:
report_exception(e)
return channel