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

Notifications into the queue #1931

Merged
merged 6 commits into from
Mar 27, 2020
Merged

Conversation

luceos
Copy link
Member

@luceos luceos commented Nov 13, 2019

Forces notifications into a dedicated SendNotificationsJob and passed to the queue
One static method re-used in the job ::getAttributes, is that okay or use a trait?
Do we want to use this solution and refactor into a better Hub after stable, postpone this implementation or use it in b11?

Fixes #1869

Changes proposed in this pull request:

Forces all notifications into the queue, not just those from subscriptions. Guaranteeing a more streamlined user experience.

Reviewers should focus on:

  • Static method call from NotificationSyncer is reused on the SendNotificationsJob, the ::getAttribute. Is this okay or do we want to use a trait?
  • Do we want to use this solution and plan out a better notification hub for after stable?
  • This implementation assumes all notification channels are only async, this implementation works well with that assumption.

I decided against trying to introduce Laravel notifications channels, because that would bloat our app and increase the weight of this implementation too much.

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

@dsevillamartin
Copy link
Member

Do we want to use this solution and plan out a better notification hub for after stable?

Probably, yeah.

This implementation assumes all notification channels are only async

What about the sync queue? We can't assume notification channels are async if there's only ne other queue implementation available for Flarum right now - and it's not even an official one

What problems does this implementation have with the sync queue? As far as I can tell while skimming the code, it should work fine with it.

@luceos
Copy link
Member Author

luceos commented Nov 14, 2019

What I considered is that if any of the broadcast channel require or expect immediate user interaction, they will fail. I agree there should be no issue running these notifications with sync up until a certain number of recipients is reached and a specific amount of channels is configured. The longer processing the notifications takes the more likely the XHR will time out and the user receives no feedback on whatever they were actually doing..

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Cool stuff! Great approach for moving all our emails into the sync queue at once, much better than my modest proposal in #1869. 😉

A few comments - let's discuss this, I am curious to hear what you think.

src/Notification/Event/Notifying.php Outdated Show resolved Hide resolved
src/Queue/AbstractJob.php Show resolved Hide resolved
src/Queue/AbstractJob.php Outdated Show resolved Hide resolved
src/Notification/NotificationSyncer.php Outdated Show resolved Hide resolved
src/Notification/NotificationSyncer.php Outdated Show resolved Hide resolved
src/Notification/Job/SendNotificationsJob.php Outdated Show resolved Hide resolved
src/Notification/Job/SendNotificationsJob.php Outdated Show resolved Hide resolved
src/Notification/Job/SendNotificationsJob.php Show resolved Hide resolved
@franzliedke
Copy link
Contributor

Just noticed this will also fix #978. 💪

@luceos
Copy link
Member Author

luceos commented Nov 19, 2019

@franzliedke I decided in favor of an abstract, can give an opinion on this?

@franzliedke
Copy link
Contributor

Rebased, diff is looking much better now.

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Good job, what a huge step forward! 👏

However, if I am not misunderstanding things, a small inconsistency got introduced - probably in the latest refactoring step.

src/Notification/Job/SendNotificationsJob.php Outdated Show resolved Hide resolved
src/Notification/NotificationSyncer.php Outdated Show resolved Hide resolved
@franzliedke
Copy link
Contributor

Okay, we cannot quite consider #978 to be fixed with this yet - this "only" tackles notification emails. There are a few other emails, so those need to be queued as well. See #1920 for more discussion on that topic.

Forces notifications into a dedicated SendNotificationsJob and passed
to the queue.

- One static method re-used in the job ::getAttributes, is that okay or
  use a trait?
- Do we want to use this solution and refactor into a better Hub after
  stable, postpone this implementation or use it in b11?
@franzliedke franzliedke force-pushed the dk/1869-queue-notifications branch 2 times, most recently from 2177a02 to 9c0c3b7 Compare March 27, 2020 15:18
luceos and others added 5 commits March 27, 2020 16:22
This separates sending each individual mail, thus hardening the app.
There are still many improvements possible in this code, e.g. chaining
these commands, making emails just another notification type and
listening to the Notify event instead. We can postpone this to a later
stable release.
As discussed with @luceos, let's add this once the use case comes up. It
might be a left-over from a previous state of this PR anyway.
This gives extension authors time to add the new `getAttributes()`
method to their `BlueprintInterface` implementations.

The layer itself is easy to remove in beta.14.
Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Had a call with @luceos in the afternoon and made a few tweaks. I am happy with this now.

We will need the changes from flarum/subscriptions#21 to also move the potentially costly call to the NotificationSyncer for post subscription notifications to the queue.

@franzliedke franzliedke merged commit 29bdd47 into master Mar 27, 2020
@franzliedke franzliedke deleted the dk/1869-queue-notifications branch March 27, 2020 22:06
franzliedke added a commit that referenced this pull request Apr 3, 2020
No need for breaking backwards compatibility here - encapsulating the
logic for `getAttributes()` in one place turns out to be quite useful.

Refs #1931.
@franzliedke
Copy link
Contributor

I removed by weird BlueprintBC backwards compatibility layer again, see 1cda9dc - having getAttributes() in one place is actually quite nice.

I moved all of it to the Notification model, though - the getAttributes() stuff was only ever called in conjunction with fetching or creating notification models, so this felt like it belongs there.

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.

[Subscriptions] Queue "new post" email
3 participants