Class: MailRoom::MicrosoftGraph::Connection

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

Constant Summary collapse

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, #stopped?

Constructor Details

#initialize(mailbox) ⇒ Connection

Returns a new instance of Connection.



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

def initialize(mailbox)
  super

  reset
  setup
end

Instance Attribute Details

#throttled_countObject

Returns the value of attribute throttled_count.



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

def throttled_count
  @throttled_count
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#waitObject



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

def wait
  return if stopped?

  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