readthedocs.org icon indicating copy to clipboard operation
readthedocs.org copied to clipboard

Email: render template before sending it to the task

Open stsewd opened this issue 1 year ago • 7 comments

The txt formats are the same as the html ones, but with tags removed and small changes to include links along the text.

Closes https://github.com/readthedocs/readthedocs.org/issues/9466


:books: Documentation previews :books:

  • User's documentation (docs): https://docs--9538.org.readthedocs.build/en/9538/
  • Developer's documentation (dev): https://dev--9538.org.readthedocs.build/en/9538/

stsewd avatar Aug 23 '22 16:08 stsewd

@agjohnson

These emails were all templated and sent from a task to avoid synchronous delays with web requests.

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?

humitos avatar Aug 25 '22 16:08 humitos

Does Celery have a setting for the max size of the message that we can check?

Didn't find a setting related to that

stsewd avatar Aug 25 '22 19:08 stsewd

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.

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.

agjohnson avatar Aug 29 '22 17:08 agjohnson

@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?

humitos avatar Sep 06 '22 09:09 humitos

@stsewd have you tested this locally to check the rendered template does fit on the Celery queue without problems?

It works locally.

stsewd avatar Sep 06 '22 16:09 stsewd

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.

stsewd avatar Sep 06 '22 16:09 stsewd

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.

agjohnson avatar Sep 06 '22 17:09 agjohnson

Re: queue object and size limits

The rendered email content is likely smaller than a Django context object, since it for instance contains request from django.template.context_processors.request.

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.

benjaoming avatar Oct 04 '22 14:10 benjaoming