2022-07-23 23:45:48 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Mailgun
|
|
|
|
module WebhookProcessors
|
|
|
|
class FailureLogger < Base
|
|
|
|
def execute
|
2022-10-11 01:57:18 +05:30
|
|
|
log_failure if permanent_failure_over_threshold? || temporary_failure_over_threshold?
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
def permanent_failure_over_threshold?
|
|
|
|
payload['event'] == 'failed' && payload['severity'] == 'permanent' &&
|
|
|
|
Gitlab::ApplicationRateLimiter.throttled?(:permanent_email_failure, scope: payload['recipient'])
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def temporary_failure_over_threshold?
|
|
|
|
payload['event'] == 'failed' && payload['severity'] == 'temporary' &&
|
|
|
|
Gitlab::ApplicationRateLimiter.throttled?(:temporary_email_failure, scope: payload['recipient'])
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def log_failure
|
|
|
|
Gitlab::ErrorTracking::Logger.error(
|
|
|
|
event: 'email_delivery_failure',
|
|
|
|
mailgun_event_id: payload['id'],
|
|
|
|
recipient: payload['recipient'],
|
|
|
|
failure_type: payload['severity'],
|
|
|
|
failure_reason: payload['reason'],
|
|
|
|
failure_code: payload.dig('delivery-status', 'code'),
|
|
|
|
failure_message: payload.dig('delivery-status', 'message')
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|