debian-mirror-gitlab/lib/gitlab/mailgun/webhook_processors/failure_logger.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.1 KiB
Ruby
Raw Normal View History

2022-07-23 23:45:48 +05:30
# frozen_string_literal: true
module Gitlab
module Mailgun
module WebhookProcessors
class FailureLogger < Base
def execute
log_failure if permanent_failure? || temporary_failure_over_threshold?
end
def permanent_failure?
payload['event'] == 'failed' && payload['severity'] == 'permanent'
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