Avoid rate limits in reseed-auth0 cron job - #840
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Auth0 throttling remains insufficient, and pacing holds the database transaction open.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates Auth0 reseeding with API throttling, additional seed data, and documentation changes.
Changes:
- Adds delays around Auth0 Management API calls.
- Adds organization and camp/base seed data.
- Updates reseeding instructions.
File summaries
| File | Summary |
|---|---|
README.md |
Updates instructions; remaining documentation path and port inconsistencies need correction. |
library/lib/auth0.php |
Adds delays, but the 200 ms interval does not sufficiently limit all API calls. |
db/init.sql |
Adds organization and camp/base seed records. |
cron/reseed-auth0.php |
Adds role-sync delays, but pacing is too fast and occurs inside the database transaction. |
Review details
Suppressed comments (3)
README.md:60
- The canonical README path was corrected to
/cron/reseed-auth0.php, butdocs/auth0.md:62still directs users to/reseed-auth0.php;gcloud-entry.phponly routes the former and returns 404 for the latter. Please update the remaining Auth0 reseeding documentation in the same change.
6. If you want to connect new bases and organisations from the seed to Auth0 and populate the `cms_*` db tables, open a browser and request `http://localhost:8100/cron/reseed-auth0.php` (`init.sql` must contain the new bases)
README.md:60
- The PHP development-server setup documented above runs on port 8000, but this instruction hardcodes Docker's port 8100. Following the non-Docker setup therefore sends the reseed request to the wrong server; document both URLs or make the host/port depend on the selected setup.
6. If you want to connect new bases and organisations from the seed to Auth0 and populate the `cms_*` db tables, open a browser and request `http://localhost:8100/cron/reseed-auth0.php` (`init.sql` must contain the new bases)
cron/reseed-auth0.php:38
- This delay runs inside the transaction opened at
db_transactionon line 18. By this point the reseed has inserted/updated CMS role rows, so each 200 ms pause keeps those locks open until the entire Auth0 user sync finishes; a full run can therefore block concurrent role/group changes. Please avoid holding the database transaction while pacing the remote API, or split the database and Auth0 phases.
usleep(200000);
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| while ($row = db_fetch($result)) { | ||
| $role = getRolesByName($row['auth0_role_name']); | ||
| db_query('UPDATE cms_usergroups_roles SET auth0_role_id = :id WHERE auth0_role_name = :rolename', ['id' => $role['id'], 'rolename' => $row['auth0_role_name']]); | ||
| usleep(200000); |
| } | ||
|
|
||
| $response = $mgmtAPI->users()->update($auth0UserId, $auth0UserData); | ||
| usleep(200000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://trello.com/c/SLY8WbZ7