Class: InstagramConnect::RefreshTokensJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/instagram_connect/refresh_tokens_job.rb

Overview

Refreshes access tokens for active accounts before they expire. Schedule it daily (e.g. via Solid Queue recurring tasks). One account's failure never aborts the batch. Accounts on a non-expiring path (Facebook-Login) simply keep their token — refresh_token there is a no-op.

Constant Summary collapse

DEFAULT_WINDOW =

seconds

7 * 24 * 60 * 60

Instance Method Summary collapse

Instance Method Details

#perform(within: DEFAULT_WINDOW) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/instagram_connect/refresh_tokens_job.rb', line 11

def perform(within: DEFAULT_WINDOW)
  threshold = Time.current + within
  Account.active.token_expiring_before(threshold).find_each do ||
    .refresh_access_token!
  rescue StandardError => e
    InstagramConnect.configuration.logger&.error(
      "[instagram_connect] token refresh failed for account #{.id}: #{e.message}"
    )
  end
end