Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #108 from pmclanahan/fix-send-message-no-exist-error
Browse files Browse the repository at this point in the history
No longer raise errors for missing message IDs.
  • Loading branch information
pmac committed Sep 29, 2014
2 parents 895dde4 + 4fc8069 commit 97cbe33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion news/backends/exacttarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
UnauthorizedException


ET_TIMEOUT = getattr(settings, 'EXACTTARGET_TIMEOUT', 3)
ET_TIMEOUT = getattr(settings, 'EXACTTARGET_TIMEOUT', 5)


class SudsDjangoCache(Cache):
Expand Down
7 changes: 3 additions & 4 deletions news/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def update_fxa_info(email, lang, fxa_id, source_url=None):

record['TOKEN'] = token

apply_updates(settings.EXACTTARGET_DATA, record)
welcome = mogrify_message_id(FXACCOUNT_WELCOME, lang, welcome_format)
send_message(welcome, email, token, welcome_format)
apply_updates(settings.EXACTTARGET_DATA, record)


@et_task
Expand Down Expand Up @@ -546,10 +546,9 @@ def send_message(message_id, email, token, format):
# Better error messages for some cases. Also there's no point in
# retrying these
if 'Invalid Customer Key' in e.message:
# Raise the error so it gets logged once, but remember it's a
# bad message ID so we don't try again during this process.
# remember it's a bad message ID so we don't try again during this process.
BAD_MESSAGE_ID_CACHE.set(message_id, True)
raise BasketError("ET says no such message ID: %r" % message_id)
return
elif 'There are no valid subscribers.' in e.message:
raise BasketError("ET says: there are no valid subscribers.")
# we should retry
Expand Down
13 changes: 8 additions & 5 deletions news/tests/test_send_welcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from news.backends.common import NewsletterException
from news.models import Newsletter
from news.tasks import BasketError, confirm_user, mogrify_message_id, \
send_message
from news.tasks import confirm_user, mogrify_message_id, send_message


class TestSendMessage(TestCase):
Expand All @@ -18,10 +17,14 @@ def test_caching_bad_message_ids(self, mock_ExactTarget):
mock_et.trigger_send.side_effect = exc

message_id = "MESSAGE_ID"
# Should only raise BaseketError once
with self.assertRaises(BasketError):
for i in range(10):
send_message(message_id, 'email', 'token', 'format')
send_message(message_id, 'email', 'token', 'format')

mock_et.trigger_send.assert_called_once_with('MESSAGE_ID', {
'EMAIL_ADDRESS_': 'email',
'TOKEN': 'token',
'EMAIL_FORMAT_': 'format',
})


class TestSendWelcomes(TestCase):
Expand Down

0 comments on commit 97cbe33

Please sign in to comment.