fix: apply backoff for imap authentication errors

This commit is contained in:
Tanmay Deep Sharma
2026-03-02 11:21:14 +05:30
parent 4548bdcf7b
commit a7d14905de
2 changed files with 8 additions and 9 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ class Inboxes::FetchImapEmailsJob < MutexApplicationJob
channel.clear_backoff!
rescue Imap::AuthenticationError => e
Rails.logger.error "#{channel.backoff_log_identifier} authentication error : #{e.message}"
channel.authorization_error!
channel.apply_backoff!
rescue *ExceptionList::IMAP_TRANSIENT_EXCEPTIONS => e
Rails.logger.error "#{channel.backoff_log_identifier} transient error : #{e.message}"
channel.apply_backoff!
@@ -89,13 +89,13 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
end
context 'when authentication error is raised' do
it 'calls authorization_error! on the channel' do
it 'calls apply_backoff! on the channel' do
allow(Imap::FetchEmailService).to receive(:new).and_raise(Imap::AuthenticationError)
allow(imap_email_channel).to receive(:authorization_error!)
allow(imap_email_channel).to receive(:apply_backoff!)
described_class.perform_now(imap_email_channel)
expect(imap_email_channel).to have_received(:authorization_error!)
expect(imap_email_channel).to have_received(:apply_backoff!)
end
end
@@ -120,7 +120,7 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
end
context 'when IMAP OAuth errors out' do
it 'marks the connection as requiring authorization' do
it 'calls authorization_error! on the channel' do
error_response = double
oauth_error = OAuth2::Error.new(error_response)
@@ -128,12 +128,11 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
.with(channel: microsoft_imap_email_channel, interval: 1)
.and_raise(oauth_error)
allow(Redis::Alfred).to receive(:incr)
expect(Redis::Alfred).to receive(:incr)
.with("AUTHORIZATION_ERROR_COUNT:channel_email:#{microsoft_imap_email_channel.id}")
allow(microsoft_imap_email_channel).to receive(:authorization_error!)
described_class.perform_now(microsoft_imap_email_channel)
expect(microsoft_imap_email_channel).to have_received(:authorization_error!)
end
end