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

Use queues for sending emails #978

Closed
tobyzerner opened this issue Jun 9, 2016 · 14 comments · Fixed by #2096
Closed

Use queues for sending emails #978

tobyzerner opened this issue Jun 9, 2016 · 14 comments · Fixed by #2096

Comments

@tobyzerner
Copy link
Contributor

Sometimes submitting a post can be slow because you have to wait for Flarum to send notification emails on the backend before it sends back the 200 OK response.

We should look at using Laravel's Queue component (or similar) to send emails asynchronously. Of course it will be optional as many shared hosts won't have the ability to run a queue worker in the background.

@tobyzerner tobyzerner added this to the 0.1.0 milestone Jun 9, 2016
@franzliedke
Copy link
Contributor

Yes, please. Using the sync driver by default. We can improve this even more, by using one of my two experimental approaches from a long time ago: tardiqueue and threadqueue.

Both (but probably mostly the first one) are aimed at providing a more performant "poor man's queue" system for use with e.g. shared hosts.

@luceos
Copy link
Member

luceos commented Sep 11, 2016

@franzliedke something you might need to consider is the limitation by many shared hosts of the number of processes allowed per hosting plan/website. A common OS that implements this is CloudLinux.

@franzliedke
Copy link
Contributor

@luceos Laravel's sync driver is basically just a dummy - it executes a job immediately instead of pushing it onto a queue. It's basically the poor man's queue adapter. So is my tardiqueue extension, it's just a little more advanced.

@luceos
Copy link
Member

luceos commented Sep 12, 2016

Yes I understand, I was referring to the threadqueue solution @franzliedke ;)

@franzliedke
Copy link
Contributor

Gotcha, yeah, that should only be used where possible.

@franzliedke
Copy link
Contributor

That's highly experimental anyhow.

@luceos
Copy link
Member

luceos commented Dec 29, 2016

Would like to take a shot at this if you're ok with it @flarum/core.

todo

  • Add queue to ioc.
  • Set queue driver to sync per default.
  • Have all background tasks run through queue if possible, but at least the mail sending.

Would it be acceptable to simply call the QueueServiceProvider of the Illuminate\Queue package?

@franzliedke
Copy link
Contributor

@luceos Please do. 👍

TODO list looks great.

Please create a stripped-down version of the service provider - the one from Laravel registers all the drivers in order to be as configurable as possible (and some console commands which we don't need for now). Ours should only set up the sync driver for now - at one point we will have a config flag that will be used to switch to another driver instead. The DatabaseServiceProvider might serve as inspiration.

@luceos
Copy link
Member

luceos commented Dec 29, 2016

First implementation already sends over sync. I've extended the illuminate service provider and the QueueManager. I'll see if I can make a non-extended provider.

@luceos
Copy link
Member

luceos commented Dec 29, 2016

Some thoughts I had:

  • I've created a DispatchJobsTrait that mirrors the behavior seen in the DispathEventsTrait, but I'm not sure that's the best of solving sending jobs.
  • I'm using the Bus Dispatcher of Laravel to send Jobs into the queue. On hindsight, this might not be the best way of doing so.
  • I've created a generic MailJob which allows sending mails to the queue with body, subject and to. We might need to extend this further or even require adding a Message object as argument.
  • As discussed above, the service provider needs cleaning and/or stripping.
  • The Queue requires an Encrypter, I've copied the implementation Laravel uses for now, but there are two things here that we need to decide on:
    • The cipher is now hardcoded to AES-256-CBC that's what Laravel does too,
    • The app_key is now using an md5 of the url, I forgot whether Flarum has its own key somewhere, please advise.

Anything else?

@luceos
Copy link
Member

luceos commented Jan 2, 2017

@franzliedke could you share you thoughts on the above once you have the opportunity to do so? Greatly appreciated.

@franzliedke
Copy link
Contributor

@luceos Do you still need anything here, or is the feedback in the PR enough?

@luceos luceos self-assigned this Feb 13, 2017
@luceos
Copy link
Member

luceos commented Feb 13, 2017

No it's fine, I'll patch it up asap. I've self assigned this issue.

@luceos
Copy link
Member

luceos commented Apr 6, 2019

Wow I even looked into this. I think I have an idea how to move forward with this. Dispatch now in laravel is also pretty much like a sync driver.. Will give this a shot again soon, might make bokt/flarum-queue deprecated.

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

Successfully merging a pull request may close this issue.

3 participants