mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added retry for the Reddit flair, also some better error checking
This commit is contained in:
@@ -83,11 +83,22 @@ def queue_account_updates(update_delay=604800, batch_size=50):
|
||||
update_account.delay(username=acc.pk)
|
||||
|
||||
|
||||
@task(ignore_result=True)
|
||||
def update_user_flair(username, character_name):
|
||||
class update_user_flair(Task):
|
||||
"""
|
||||
Updates a user's flair on Reddit
|
||||
"""
|
||||
|
||||
default_retry_delay = 5 * 60 # retry in 5 minutes
|
||||
ignore_result = True
|
||||
|
||||
def run(self, username, character_name, **kwargs):
|
||||
try:
|
||||
ib = Flair(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
||||
ib.set_flair(settings.REDDIT_SUBREDDIT, username, character_name, '')
|
||||
except (HTTPError, URLError), exc:
|
||||
logger.error("Error updating flair, queueing for retry")
|
||||
update_user_flair.retry(args=[username, character_name], kwargs=kwargs, exc=exc)
|
||||
pass
|
||||
except LoginError, exc:
|
||||
logger.error("Error logging into Reddit")
|
||||
|
||||
|
||||
@@ -293,6 +293,7 @@ def primarychar_change(request):
|
||||
@login_required
|
||||
def toggle_reddit_tagging(request):
|
||||
profile = request.user.get_profile()
|
||||
if profile.primary_character:
|
||||
profile.tag_reddit_accounts = not profile.tag_reddit_accounts
|
||||
profile.save()
|
||||
if profile.tag_reddit_accounts:
|
||||
@@ -307,4 +308,7 @@ def toggle_reddit_tagging(request):
|
||||
name = ''
|
||||
for acc in request.user.redditaccount_set.all():
|
||||
update_user_flair.delay(acc.username, name)
|
||||
else:
|
||||
messages.add_message(request, messages.ERROR, "You need to set a primary character before using this feature!")
|
||||
|
||||
return redirect('sso.views.profile')
|
||||
|
||||
Reference in New Issue
Block a user