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

run the users-refresher-lambda every minute #123

Merged
merged 3 commits into from
Mar 31, 2022

Conversation

twrichards
Copy link
Collaborator

@twrichards twrichards commented Mar 30, 2022

https://trello.com/c/RIfC9Vqc/550-run-pinboard-user-refresher-lambda-on-permission-change

Previously the users-refresher-lambda ran on a 6 hourly schedule (to keep load on google APIs low), which kept our list of users (needed for name resolution, avatars and to populate the mentions suggestions) somewhat up to date. However the recent live blog pilots highlighted the fact that we still needed to run this lambda manually after a permission change to avoid waiting up to 6 hours before users could safely use pinboard.

Initially we hoped to trigger the users-refresher-lambda whenever permissions actually change (see #118) however without adding lots of complex infrastructure (including making changes to guardian/permissions) this is not possible.

What does this change?

Instead, here we increase the frequency of the users-refresher-lambda schedule to every minute and with a payload of {isProcessPermissionChangesOnly: true} which checks there are actually pinboard permission changes and looks-up only those against the Google APIs. Note that users who have the permission removed are marked as isMentionable: false

We also introduce another schedule, which daily does a full run to ensure users who've left are marked as isMentionable: false.

Mention suggestions are now only populated with users with isMentionable: true. This new approach replaces the previous TTL concept (see #46 and #50) and retains user rows indefinitely, preferring a flag which is more explicit (and also makes the impending move away from Dynamo to a relational DB easier).

How to test

With this deployed to CODE

  • change some non-pinboard permissions in CODE and see NO CHANGE TO PINBOARD PERMISSIONS, exiting early in the logs
  • add the pinboard permission for someone, and see DETECTED PINBOARD PERMISSIONS ADDED FOR in the logs (followed by the usual log lines about upserting).
  • remove the pinboard permission for someone, and see DETECTED PINBOARD PERMISSIONS REMOVED FOR in the logs (followed by the usual log lines about upserting).
  • if left overnight (or run manually), see FULL RUN in the logs (followed by the usual log lines about upserting).

How can we measure success?

No dev intervention required when CP add new users to pinboard, and they can start using pinboard safely within a minute.

Have we considered potential risks?

This will cost a touch more, but since pinboard currently costs only a few cents per month - this is OK.

@twrichards twrichards marked this pull request as draft March 30, 2022 12:10
@twrichards twrichards force-pushed the trigger-user-refresher-on-permission-change branch 14 times, most recently from 4622d45 to 4c46d85 Compare March 31, 2022 08:46
@twrichards twrichards marked this pull request as ready for review March 31, 2022 08:47
@twrichards twrichards requested review from andrew-nowak and a team March 31, 2022 08:47
@twrichards twrichards force-pushed the trigger-user-refresher-on-permission-change branch from 4c46d85 to 71d3566 Compare March 31, 2022 11:44
);

if (!emailsOfUsersWithPinboardPermission) {
throw Error("Could not get list of users with 'pinboard' permission.");
}

const isNightlyFullRun = now.getHours() === 0 && now.getMinutes() === 0;
Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth adding a parameter to allow manually running a full run in case of errors/emergencies?

Copy link
Collaborator Author

@twrichards twrichards Mar 31, 2022

Choose a reason for hiding this comment

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

yeah I actually was thinking about something like that. Perhaps two schedules...

  1. every minute, sends some isProcessPermissionChangesOnly: true flag in the payload
  2. every 24 hours, no payload (i.e. same as a manual run)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in c4c5d67

@twrichards twrichards force-pushed the trigger-user-refresher-on-permission-change branch from 01b4e8e to cefb868 Compare March 31, 2022 12:41
…ually pinboard permission changes before hitting Google APIs (except the midnight invocation, where we do a full update to bump the TTLs on the records)
…ffected) email rather than iterating through all the guardian users (500 at a time)
@twrichards twrichards force-pushed the trigger-user-refresher-on-permission-change branch from cefb868 to 9364c2e Compare March 31, 2022 12:46
…rocessPermissionChangesOnly: true` in the payload) and every 24 hours (no payload, so should do full run)
@twrichards twrichards force-pushed the trigger-user-refresher-on-permission-change branch from 9364c2e to c4c5d67 Compare March 31, 2022 12:53
@twrichards twrichards merged commit 53cd191 into main Mar 31, 2022
@twrichards twrichards deleted the trigger-user-refresher-on-permission-change branch March 31, 2022 13:29
@prout-bot
Copy link
Collaborator

Overdue on PROD (merged by @twrichards 5 minutes and 4 seconds ago) What's gone wrong?

@prout-bot
Copy link
Collaborator

Seen on PROD (merged by @twrichards 6 minutes and 8 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants