Class: MailRoom::MicrosoftGraph::Connection

Inherits:
Connection
  • Object
show all
Defined in:
lib/mail_room/microsoft_graph/connection.rb

Constant Summary collapse

SCOPE =
'https://graph.microsoft.com/.default'
NEXT_PAGE_KEY =
'@odata.nextLink'
DEFAULT_POLL_INTERVAL_S =
60
TooManyRequestsError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Attributes inherited from Connection

#mailbox, #new_message_handler

Instance Method Summary collapse

Methods inherited from Connection

#on_new_message, #quit

Constructor Details

#initialize(mailbox) ⇒ Connection

Returns a new instance of Connection.



17
18
19
20
21
22
# File 'lib/mail_room/microsoft_graph/connection.rb', line 17

def initialize(mailbox)
  super

  reset
  setup
end

Instance Attribute Details

#throttled_countObject

Returns the value of attribute throttled_count.



15
16
17
# File 'lib/mail_room/microsoft_graph/connection.rb', line 15

def throttled_count
  @throttled_count
end

#tokenObject

Returns the value of attribute token.



15
16
17
# File 'lib/mail_room/microsoft_graph/connection.rb', line 15

def token
  @token
end

Instance Method Details

#waitObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mail_room/microsoft_graph/connection.rb', line 24

def wait
  process_mailbox

  @throttled_count = 0
  wait_for_new_messages
rescue TooManyRequestsError => e
  @throttled_count += 1

  @mailbox.logger.warn({ context: @mailbox.context, action: 'Too many requests, backing off...', backoff_s: backoff_secs, error: e.message, error_backtrace: e.backtrace })

  backoff
rescue IOError => e
  @mailbox.logger.warn({ context: @mailbox.context, action: 'Disconnected. Resetting...', error: e.message, error_backtrace: e.backtrace })

  reset
  setup
end