在Heroku + Django上长时间运行的文件生成 [英] Long running file generation on Heroku + Django

查看:88
本文介绍了在Heroku + Django上长时间运行的文件生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Heroku上运行的Django应用.用户可以以Excel/PDF格式下载各种报告.其中一些报告可能需要一分钟才能生成,这意味着我需要在后台/工作流程中创建它们.我已经将芹菜和redis一起设置为消息代理.

I have a Django app running on Heroku. The user can download various reports in either Excel/PDF format. Some of these reports can take a minute to generate, which means I need to create them on a background/worker process. I already have celery setup together with redis as the message broker.

我的问题是解决此问题的最佳方法是什么?到目前为止,这是我的主意.

My question is what is the best way to deal with this? This is my idea so far.

  1. 用户启动报告后,页面某处会显示正在生成,请稍候".
  2. 然后生成文件并将其保存在临时位置.可能在S3或某种缓存中.
  3. 然后我轮询一个特定的位置,一旦文件准备好,它将返回文件存储位置的url.此时,请稍候"变成一个链接.
  4. 每天我都会使用生命周期规则清理S3存储桶

我敢肯定这是可行的,但这似乎需要付出很大的努力,而且也不是最佳的用户体验.当前,一旦准备好出现下载对话框,用户便会等待文件.只要在30秒内返回文件,这种方法就可以正常工作.

I'm sure this will work, but it just seems like a lot of effort and not the best user experience either. Currently the user just waits for the file once ready the download dialog appears. This works fine as long as the file is returned within 30 seconds, which isn't always the case.

我还考虑过通过电子邮件将文件发送给用户,但是我认为这不是一个好方法.

I've also thought about emailing the file to the user, but I don't think this is a great approach.

有人有更好的建议吗?

推荐答案

我当然不会使用电子邮件.

I would certainly not use e-mail.

顺便说一句,从UX的角度看,我看不出您的方法有什么问题.为此,等待文件生成肯定比超时或等待30秒开始下载要早.

With that out of the way, I don't see what's wrong with your approach from a UX perspective. Waiting for a file to be generated certainly beats timing out or waiting for 30 seconds before download starts, for that matter.

根据用例,您可以(a)提供估计的时间,直到生成报告为止(可能是不可能的),和/或(b)使用户登陆到具有报告详细信息的其他页面上(可能使用HTML5历史记录API 使其无缝).

Depending on the use case, you could (a) provide an estimated time till the report is generated (may not be possible) and/or (b) have the user land on a different page with report details (possibly using the HTML5 history API to make it seamless).

这篇关于在Heroku + Django上长时间运行的文件生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆