Repository navigation
Email: render template before sending it to the task - #9538
Conversation
ed93d2b to
8642e5a
Compare
7b8854a to
d5307af
Compare
| self.assertEqual(mock_send_email.call_count, 1) | ||
| mock_send_email.assert_has_calls([ | ||
| mock.call( | ||
| request=mock.ANY, |
There was a problem hiding this comment.
the request parameter isn't being used at all withing the send email function or task, I think we should just remove it.
humitos
left a comment
There was a problem hiding this comment.
I think this is fine. I left some comments to talk a little more before merging, but I think this is good work and going in the right direction.
| # We send only what we need from the Django model objects here to avoid | ||
| # serialization problems in the ``readthedocs.core.tasks.send_email_task`` |
There was a problem hiding this comment.
If we are not doing this anymore, we should probably also stop creating the context dictionary, and just send the Django objects instead. Then, from the other function we can grab whatever we need from these objects.
There was a problem hiding this comment.
If we are not doing this anymore, we should probably also stop creating the context dictionary, and just send the Django objects instead.
Do you mean just for this case? If you mean for everything, we still need to pass some additional things in the context that aren't in just one object.
| self.assertEqual(mock_send_email.call_count, 1) | ||
| mock_send_email.assert_has_calls([ | ||
| mock.call( | ||
| request=mock.ANY, |
agjohnson
left a comment
There was a problem hiding this comment.
Looks good! Reminder that there might be emails hiding in ext as well, if you haven't already looked.
I'll let @humitos give the 👍 on this, as you'll be closer to release and QA, but seems like a better approach. These emails were all templated and sent from a task to avoid synchronous delays with web requests. So, just doing the templating step before inserting into our task queue doesn't seem like a huge change we need to be worried about.
…main_configuration_email.txt Co-authored-by: Anthony <[email protected]>
This is a good point that I didn't think about. I don't think it will be a problem since these templates are small and I don't think they will take too much time to render that could produce a timeout on the web request. @stsewd One thing that we should test before deploying this is if the Celery message inserted in the queue is not too big due the whole HTML + txt files are going to be on the message itself. Does Celery have a setting for the max size of the message that we can check? |
Didn't find a setting related to that |
Aye, I feel this is safe as well, though don't quote me on this either. At some point we must have had some variable that required an external lookup or something that would block the web request during template render. |
|
@stsewd @agjohnson are we happy moving forward with this PR? @stsewd have you tested this locally to check the rendered template does fit on the Celery queue without problems? |
It works locally. |
|
Another approach would be to change the notifications classes to pass the attributes of the object to be used in the context instead of the object itself, but that feels more error-prone than just passing the object. |
|
I don't have any objections, I was just raising a note about the performance. If you all feel this is safe, I'd agree this shouldn't be an issue. @humitos brings up a good point on the Celery internals. I'm not aware of a Celery specific limit here, but we are using AWS Elasticache in production (as opposed to Redis in development). Elasticache, or Elasticache + Celery, could have different limits here. |
|
Re: queue object and size limits The rendered email content is likely smaller than a Django context object, since it for instance contains If there is a known limit to celery task data, it would be nice of Celery to raise that exception. Moreover, Redis and RabbitMQ both have a maximum value size of 512 MB: https://stackoverflow.com/a/5624569/405682 I was reading a bit about Kombu, and I think there's some "Quality of Service" involved when a worker receives messages as well. For all I can tell, these message brokers and task queues are designed to handle significantly larger task data than some text email. I don't think this is an issue -- and if it is, then we might find more issues. |
The txt formats are the same as the html ones,
but with tags removed and small changes to include
links along the text.
Closes #9466
📚 Documentation previews 📚
docs): https://docs--9538.org.readthedocs.build/en/9538/dev): https://dev--9538.org.readthedocs.build/en/9538/