Skip to content

Commit

Permalink
Merge pull request #6238 from gitcoinco/timeouterrors
Browse files Browse the repository at this point in the history
Handle Prod Timeout Worker Approve Timeout Errors
  • Loading branch information
owocki authored Mar 16, 2020
2 parents 84bf94b + 0a25dfb commit 067161c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def preprocess(request):
'github_handle': request.user.username if user_is_authenticated else False,
'email': request.user.email if user_is_authenticated else False,
'name': request.user.get_full_name() if user_is_authenticated else False,
'last_chat_status': request.user.profile.last_chat_status if (hasattr(request.user, 'profile') and user_is_authenticated) else False,
'last_chat_status':
request.user.profile.last_chat_status if
(hasattr(request.user, 'profile') and user_is_authenticated) else False,
'raven_js_version': settings.RAVEN_JS_VERSION,
'raven_js_dsn': settings.SENTRY_JS_DSN,
'release': settings.RELEASE,
Expand Down
21 changes: 21 additions & 0 deletions app/app/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import email
import functools
import imaplib
import logging
import multiprocessing.pool
import os
import re
import time
Expand Down Expand Up @@ -490,3 +492,22 @@ def get_profiles_from_text(text):
username_pattern = re.compile(r'@(\S+)')
mentioned_usernames = re.findall(username_pattern, text)
return Profile.objects.filter(handle__in=mentioned_usernames).distinct()


def timeout(max_timeout):
"""Timeout decorator, parameter in seconds."""

def timeout_decorator(item):
"""Wrap the original function."""

@functools.wraps(item)
def func_wrapper(*args, **kwargs):
"""Closure for function."""
pool = multiprocessing.pool.ThreadPool(processes=1)
async_result = pool.apply_async(item, args, kwargs)
# raises a TimeoutError if execution exceeds max_timeout
return async_result.get(max_timeout)

return func_wrapper

return timeout_decorator
5 changes: 4 additions & 1 deletion app/avatar/views_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,10 @@ def save_custom_avatar(request, output):
profile.activate_avatar(custom_avatar.pk)
profile.save()
create_user_action(profile.user, 'updated_avatar', request)
messages.info(request, f'Your avatar has been updated & will be refreshed when the cache expires (every hour). Or hard refresh (Apple-Shift-R) to view it now.')
messages.info(
request,
f'Your avatar has been updated & will be refreshed when the cache expires (every hour). Or hard refresh (Apple-Shift-R) to view it now.'
)
response['message'] = 'Avatar updated'
except Exception as e:
logger.exception(e)
Expand Down
8 changes: 8 additions & 0 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import requests
import twitter
from app.utils import timeout
from economy.utils import convert_token_to_usdt
from git.utils import delete_issue_comment, org_name, patch_issue_comment, post_issue_comment, repo_name
from marketing.mails import featured_funded_bounty, send_mail, setup_lang, tip_email
Expand Down Expand Up @@ -257,6 +258,13 @@ def build_message_for_integration(bounty, event_name):


def maybe_market_to_user_slack(bounty, event_name):
try:
return maybe_market_to_user_slack_helper(bounty, event_name)
except TimeoutError as e:
logger.exception(e)

@timeout(1)
def maybe_market_to_user_slack_helper(bounty, event_name):
"""Send a Slack message to the user's slack channel for the specified Bounty.
Args:
Expand Down

0 comments on commit 067161c

Please sign in to comment.