Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFM-10286 Add re-authentication mechanism + synchronous init option #9

Merged
merged 26 commits into from
Dec 29, 2023

Conversation

erdirowlands
Copy link
Contributor

@erdirowlands erdirowlands commented Dec 22, 2023

What

  1. Adds a mechanism for the Poller job to re-authenticate before the token expires in the Platform Cache. A margin of one hour is used before token expiration.
    This is achieved by adding a new lastAuthTime item to the cache, which Poller instances can all refer to for a global understanding on when they should refresh the auth token.

  2. The SDK wouldn’t fetch flags/groups unless Polling is enabled, and Polling must be explicitly enabled. This causes two issues: 1) Client init is basically async only, so immediate evaluations will get the default until a poller instance can update the cache. 2) If polling is not enabled, then the SDK won’t ever get flags and the default will always be returned.
    This adds an optional waitForInitialzed option which adds a sync mode, and allows the SDK to fetch flags if polling is disabled. This WON'T work in a scheduled job as it will crash the job, so I've added warning to the readme.

Why

  1. Scheduled jobs that start up a client instance will try to authenticate if the SDK cannot find a token in the Platform Cache (which has a default TTL of 24 hours). The job fail with a System Exception because scheduled jobs are not able to make external callouts. A customer is hitting this issue during quiet periods, when the Platform Cache has not been refreshed by client instances started up outside of scheduled jobs.

  2. Align with other SDKs in offering a sync option, plus the SDK should fetch initial values even if polling is not enabled

Testing

  • Unit tests for CacheUpdator
  • Manual - lastAuthTime gets created in the cache.
  • Set token TTL to 1 minute, and started up a scheduled job to create a new client and evaluate. The scheduled job does not fail

@erdirowlands erdirowlands changed the title FFM-10286 FFM-10286 Add re-authentication mechanism Dec 28, 2023
@erdirowlands erdirowlands marked this pull request as ready for review December 28, 2023 15:46
Copy link

@danmack-harness danmack-harness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the TODO be addressed?

force-app/main/classes/FFAuthServiceCached.cls Outdated Show resolved Hide resolved
FFM-10286 Fix tests for last auth cache

FFM-10286 Fix types for last auth cache
FFM-10286 Retry on auth 500 errors
FFM-10286 Store last auth time as a Long: tests

FFM-10286 Store last auth time as a Long

FFM-10286 Store last auth time as a Long
FFM-10286 Fix last auth calc

FFM-10286 Add debug log
FFM-10286 Fix incorrect ms param
FFM-10286 Fix early return
FFM-10286 Update cache if polling is not enabled

FFM-10286 Update cache if polling is not enabled
FFM-10286 Don't re-poll immediately

FFM-10286 Don't re-poll immediately

FFM-10286 Don't re-poll immediately
@erdirowlands erdirowlands changed the title FFM-10286 Add re-authentication mechanism FFM-10286 Add re-authentication mechanism + synchronous init option Dec 29, 2023
@erdirowlands erdirowlands merged commit 5699ca0 into main Dec 29, 2023
1 check passed
@erdirowlands erdirowlands deleted the FFM-10286 branch December 29, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants