We have a ruby rails front end and distributed back end services running batch jobs via Redis.
The front end will acquire the initial Xero oauth2 token.
The token will expire in 30 minutes, the refresh token lasts 60 days (great), but can only be used once.
When multiple back end processes try to access Xero and the token has expired, only one can succeed all others will fail because the refresh token is single use.
Database transaction boundaries make sharing the token via the Database impractical.
I've considered the following solutions (I don't like any of them):
- A singleton to handle all xero interactions.
- Wrap xero in a retry process and check Redis for tokens that may havebeen updated by another process.
- Making the user go through oauth2 login repeatedly to obtain a tokenfor each back end process.
Unfortunately I'm new to both Ruby and Redis so specifics on implementation in this environment would be very useful.