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

Update subscriber list titles on major / minor publication events #493

Merged
merged 7 commits into from
Jan 28, 2022

Conversation

huwd
Copy link
Member

@huwd huwd commented Jan 21, 2022

Trello

Depends on

alphagov/email-alert-api#1704
(and it's release)

What

The GOV.UK Accounts team added a feature where logged in users could
subscribe to email notifications for individual pages.

SubscriberLists store the titles of those pages so that we can:

  • Render a list of subscriptions in the user's manage dashboard
  • Include the title of the subscriber list in emails alerting the user
    that the page has been unpublished. (Especially as there's no-longer a
    content item we can query for title at that point).

We record these titles when the SubscriberList is first made, however
there has not been a mechanism to update it. This is a problem as
content titles do change over time.

This PR adds a class we can use to gather information from major and
minor change messages and update the subscriber list titles using a new
Email Alert API endpoint

Other parts of email-alert-service make calls to services that use GDS
API adaptors. However they seem not to use the test helpers that ship
with the gem through webmock.

A note on test strategy

In previous work we decided to keep the testing strategy consistent
across the repo, and also avoided gds-api-test helpers. Instead we
tested with double and spys.

This got us into a bit of trouble when our parameters and payloads were
not matching the gds-api-adaptors, and reminded us how helpful those
test helpers were.

So we've introduced stubs and webmock for this test, aware this
introduces an inconsistent test strategy.

We intend to go back and refactor tests for the recently introduced
unpublication alert work. And hopefully refactor the rest of the test
suite to.

If you are far in the future and that didn't happen. Sorry! But
hopefully you at least know why these tests don't look like the others.

(1): alphagov/email-alert-api#1704

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

@huwd huwd force-pushed the update-subscriber-list-titles branch from b0351a4 to 56d94af Compare January 24, 2022 15:08
@alex9smith alex9smith force-pushed the update-subscriber-list-titles branch 2 times, most recently from 6db6f30 to 5d7388a Compare January 24, 2022 16:38
@huwd huwd changed the title (WIP) Add UpdateSubscriberList class Add UpdateSubscriberList class Jan 24, 2022
@huwd huwd requested a review from barrucadu January 24, 2022 16:42
@huwd huwd changed the title Add UpdateSubscriberList class Update subscriber list titles on major / minor publication events Jan 24, 2022
Copy link
Contributor

@barrucadu barrucadu left a comment

Choose a reason for hiding this comment

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

As a general comment, it feels a bit heavyweight adding a second major change processor for this. Not only do we have two message queues with exactly the same events in them, it could be kind of confusing to someone encountering this for the first time.

So rather than adding a second major change queue, my inclination would be to do both the content change triggering and the UpdateSubscriberList.new(document, logger).trigger inside the existing major change queue - and then call the new minor change queue minor-change-queue-consumer to fit the naming pattern of the others.

@huwd
Copy link
Member Author

huwd commented Jan 25, 2022

#493 (review)

Yeah I see what you mean, and that would be slimmer, my fear is that if we entangle the two is there any risk of errors in our updates preventing content-changes from occuring?

I can't really think of a sensible secenario, given they are both hitting the same email-alert-api.
But given the importance of content change notificaitons, and the low cost to having more workers, seemed lower risk to make separate ones?

Do you think it remains confusing even though we've given them a very explicit name here?

@barrucadu
Copy link
Contributor

barrucadu commented Jan 25, 2022

Mmm, that's a good point. In that case, I think we should have one new worker which receives all major and minor publishing events - rather than two new workers which do the same thing but with slightly different inputs.

@huwd huwd force-pushed the update-subscriber-list-titles branch from 0d16dab to 2e166af Compare January 25, 2022 16:41
Co-authored-by: Alex Whitehead-Smith <alex.whitehead-smith@digital.cabinet-office.gov.uk>
Co-authored-by: Huw Diprose <huw.diprose@digital.cabinet-office.gov.uk>
@huwd huwd force-pushed the update-subscriber-list-titles branch from 2e166af to 3b57d92 Compare January 25, 2022 16:43
@huwd
Copy link
Member Author

huwd commented Jan 25, 2022

@alex9smith and I tried that initially.
we ran into a couple of problems. Trying to trigger two .run processes from the same rake task never worked. We suspect it's because .run never returns but just keeps the process open.

So we couldn't have two running side by side from the same rake task?

Then we went down a RabbitMQ hole of "can you use regex to do multiple key matches". I found some blog posts with someone talking about "a cool hack" they'd written that seemed to suggest it's not built in. Without a super easy, standard way to match multiple routing keys (major || minor), making two with their own processors seemed like the best route?

@huwd huwd marked this pull request as ready for review January 25, 2022 16:47
@barrucadu
Copy link
Contributor

I think matching *.*.# would be fine - you get all events, the ones with titles and/or descriptions trigger an update to the list, the others don't.

@huwd
Copy link
Member Author

huwd commented Jan 25, 2022

Yeah that does work, but my concern there is that all our logger events just start clogging up logs.
For every irrelivant event there's now a validation logger saying our thing doesn't have enough info - or that it tried to check against subscriber list params and no update was needed or 404.

I don't know how many events there might be... but seems like a lot.
Future log splunkers may not thank us for it?

Having the two new processors seems to give us the targeting we want, with some admitted cruft.
I'd hope the naming makes it explicit and we've left clear commit messages here about what we are doing.

I'd hope at least that gives a solid base for a future refactor if more of these get added in future and the number of processors becomes unwealdy?

@barrucadu
Copy link
Contributor

Ok, I'm not going to die on this hill - let's go with the approach of having two new queues.

Procfile Outdated Show resolved Hide resolved
@huwd huwd force-pushed the update-subscriber-list-titles branch from e3b03ed to d7b4581 Compare January 27, 2022 14:20
alex9smith pushed a commit that referenced this pull request Jan 27, 2022
Extend the processors added in #493 to also check if the subscriber list
description has changed with a major or minor content change. If it has,
send the new version to email alert API.

These descriptions will be included in the emails sent when a page is
unpublished, so it's important that they're kept up to date.

Depends on alphagov/email-alert-api#1709
@barrucadu
Copy link
Contributor

"A note on test strategy" in 1175454 can be removed by approving #494

@barrucadu
Copy link
Contributor

I personally would squash 506ff53 into 2177521, but it's not majorly important

Procfile Outdated Show resolved Hide resolved
@huwd huwd force-pushed the update-subscriber-list-titles branch from d7b4581 to 150304c Compare January 27, 2022 15:35
huwd and others added 3 commits January 27, 2022 17:25
WHAT
====

The GOV.UK Accounts team added a feature where logged in users could
subscribe to email notifications for individual pages.

SubscriberLists store the titles of those pages so that we can:
- Render a list of subscriptions in the user's manage dashboard
- Include the title of the subscriber list in emails alerting the user
that the page has been unpublished. (Especially as there's no-longer a
content item we can query for title at that point).

We record these titles when the SubscriberList is first made, however
there has not been a mechanism to update it. This is a problem as
content titles do change over time.

This PR adds a class we can use to gather information from major and
minor change messages and update the subscriber list titles using a new
[Email Alert API endpoint](1)

Other parts of email-alert-service make calls to services that use GDS
API adaptors. However they seem not to use the test helpers that ship
with the gem through webmock.

(1): alphagov/email-alert-api#1704

Co-authored-by: Alex Whitehead-Smith <alex.whitehead-smith@digital.cabinet-office.gov.uk>
Co-authored-by: Huw Diprose <huw.diprose@digital.cabinet-office.gov.uk>
These used to be specific validations to unpublication and content
change processors.

As we're about to re-use these in a new processor (see next commit) lets
move them up to the parent class.

Co-authored-by: Alex Whitehead-Smith <alex.whitehead-smith@digital.cabinet-office.gov.uk>
Co-authored-by: Huw Diprose <huw.diprose@digital.cabinet-office.gov.uk>
Co-authored-by: Alex Whitehead-Smith <alex.whitehead-smith@digital.cabinet-office.gov.uk>
Co-authored-by: Huw Diprose <huw.diprose@digital.cabinet-office.gov.uk>
@huwd huwd force-pushed the update-subscriber-list-titles branch from 150304c to 4d53664 Compare January 27, 2022 17:25
huwd and others added 3 commits January 27, 2022 17:27
Co-authored-by: Alex Whitehead-Smith <alex.whitehead-smith@digital.cabinet-office.gov.uk>
Co-authored-by: Huw Diprose <huw.diprose@digital.cabinet-office.gov.uk>
:wq
It's now shared between two classes, a module makes more sense.
I've given it its own test file too
We ended up with nearly three identical blocks of code, this looks like
a good time to DRY it out.

Especially if we may add other similar ones in future.
@huwd huwd force-pushed the update-subscriber-list-titles branch from 4d53664 to 8865666 Compare January 27, 2022 17:27
@huwd huwd requested a review from barrucadu January 27, 2022 17:27
@huwd huwd merged commit 5416857 into main Jan 28, 2022
@huwd huwd deleted the update-subscriber-list-titles branch January 28, 2022 10:55
alex9smith pushed a commit that referenced this pull request Jan 28, 2022
Extend the processors added in #493 to also check if the subscriber list
description has changed with a major or minor content change. If it has,
send the new version to email alert API.

These descriptions will be included in the emails sent when a page is
unpublished, so it's important that they're kept up to date.

Depends on alphagov/email-alert-api#1709
alex9smith pushed a commit to alphagov/govuk-developer-docs that referenced this pull request Feb 9, 2022
We added new queues to the email-alert-service to update subscriber
list details when the page they alert for is updated. [[1]]

There are alerts that might go off for these queues that will link to
this document, so we need to add links to the queue config here.

[1]: alphagov/email-alert-service#493
alex9smith pushed a commit to alphagov/govuk-developer-docs that referenced this pull request Feb 9, 2022
We added new queues to the email-alert-service to update subscriber
list details when the page they alert for is updated. [[1]]

There are alerts that might go off for these queues that will link to
this document, so we need to add links to the queue config here.

[1]: alphagov/email-alert-service#493
alex9smith pushed a commit to alphagov/govuk-developer-docs that referenced this pull request Feb 9, 2022
We added new queues to the email-alert-service to update subscriber
list details when the page they alert for is updated. [[1]]

There are alerts that might go off for these queues that will link to
this document, so we need to add links to the queue config here.

[1]: alphagov/email-alert-service#493
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.

None yet

3 participants