Class: CentralMail::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/central_mail/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.central_mail'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#with_monitoring

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Class Method Details

.current_breaker_outage?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
# File 'lib/central_mail/service.rb', line 57

def self.current_breaker_outage?
  last_cm_outage = Breakers::Outage.find_latest(service: CentralMail::Configuration.instance.breakers_service)
  if last_cm_outage.present? && last_cm_outage.end_time.blank?
    return CentralMail::Service.new.status('').try(:status) != 200
  end

  false
end

Instance Method Details

#status(uuid_or_list) ⇒ Object

rubocop:enable Metrics/MethodLength



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/central_mail/service.rb', line 44

def status(uuid_or_list)
  body = {
    token: Settings.central_mail.upload.token,
    uuid: [*uuid_or_list].to_json
  }

  request(
    :post,
    'getStatus',
    body
  )
end

#upload(body) ⇒ Object

rubocop:disable Metrics/MethodLength



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/central_mail/service.rb', line 15

def upload(body)
  Raven.extra_context(
    request: {
      metadata: body['metadata']
    }
  )
  body['token'] = Settings.central_mail.upload.token

  response = with_monitoring do
    request(
      :post,
      'upload',
      body
    )
  end

  Raven.extra_context(
    response: {
      status: response.status,
      body: response.body
    }
  )

  StatsD.increment("#{STATSD_KEY_PREFIX}.upload.fail") unless response.success?

  response
end