Skip to content

Commit

Permalink
Retry when generic Mailchimp error occured
Browse files Browse the repository at this point in the history
  • Loading branch information
uu59 committed Mar 24, 2016
1 parent 8b789d7 commit e2a5180
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/embulk/output/mailchimp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def batch_subscribe_list(list_id, subscribers, double_optin, update_existing, re
rescue ::Mailchimp::UserUnderMaintenanceError, ::Mailchimp::TooManyConnectionsError => e
Embulk.logger.warn e.message
raise e
rescue ::Mailchimp::Error => e
raise Embulk::DataError.new(e.message)
end
end

Expand Down
41 changes: 41 additions & 0 deletions test/embulk/output/test_mailchimp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,47 @@ def test_call_finish_without_error
end
end

class TestFinish < self
setup do
stub(::Mailchimp::API).new(apikey) { }

@plugin = Mailchimp.new(
{
apikey: apikey,
list_id: list_id,
email_column: 'email',
retry_limit: retry_limit,
retry_initial_wait_sec: 0,
},
create_schema([
{name: 'email', type: :string},
]),
1
)
end

def retry_limit
3
end

def test_retry_on_mailchimp_error
client = @plugin.instance_variable_get(:@client)
stub(client).batch_subscribe_list(list_id, anything, anything, anything, anything) {
# https://bitbucket.org/mailchimp/mailchimp-api-ruby/src/37dbe82057b96e135881c9379c0a3d5f8f32bf1f/lib/mailchimp.rb?at=master&fileviewer=file-view-default#mailchimp.rb-164
raise ::Mailchimp::Error, "We received an unexpected error: <!doctype html>"
}
stub(Embulk.logger).info(anything)
mock(Embulk.logger).warn(anything).at_least(retry_limit)

@plugin.add([
["foo@example.com"]
])
assert_raise(PerfectRetry::TooManyRetry) do
@plugin.finish
end
end
end

class TestAdd < self
setup do
stub(::Mailchimp::API).new(apikey) { }
Expand Down

0 comments on commit e2a5180

Please sign in to comment.