Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/ff_bot/auth/installation_token_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ defmodule FFBot.Auth.InstallationTokenServer do

# If we did find a token, we look at the expiry date on it
[{install_id, {exp, token}}] ->
# If it expired in the past, create and return a new token
if exp <= DateTime.utc_now() do
Logger.info("Token was expired at lookup time, generating new one",
installation_id: install_id
# If it expires soon (or is already expired), create and return a new token
exp_with_margin = DateTime.add(exp, -10, :second)
if exp_with_mergin <= DateTime.utc_now() do
Logger.info("Token expires at or near lookup time, generating new one",
installation_id: install_id,
expiry: exp
)

token = generate_token(install_id)
Expand Down