将图像传递给芹菜任务 [英] Passing an image to a celery task

查看:46
本文介绍了将图像传递给芹菜任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写的应用程序的一部分允许用户上传图像,然后调整大小并自动上传到Amazon s3。目前,图片大小调整正在视图中进行,我想通过芹菜将其卸载给分散的工作人员。我的问题是将图像传递给工作人员的最佳方法是什么。我当前的想法是将图像直接存储在数据库中,然后将ID传递给工作人员并让它检索它。是否有更好的做法,然后将其临时存储在数据库中,直到可以对其进行处理?

Part of an application I'm writing allows for users to upload images which I then resize and automatically upload to amazon s3. Currently the image resizing is happening right in the view and I'd like to offload this via celery to distributed workers. My question is whats the best way to get the image to the worker. My current thinking is to store the image directly in the database and then just pass the id to the worker and have it retrieve it. Is there a better practice then temporarily storing it in the database until it can get processed?

推荐答案

如celery文档中所述,最好不要将整个对象(图像)作为参数传递,因为这会导致额外的开销。因此最好先将其保存,然后将照片id作为参数传递,将图像检索到任务中并进行大小调整/上传。

As stated in the celery docs, it is better not to pass the whole thing (image) as an argument, for this will cause extra overhead. So it is better to save it in first place, then pass the photo id as an argument, retrieve the image into the task and do the resizing / uploading.

这篇关于将图像传递给芹菜任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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