v.t*_*rey 2 django daemon virtualenv celery django-celery
我的问题如下:
我有一个 Django 应用程序,可以在上面上传文件。上传文件时,将启动 celery 任务来根据其版本处理特定队列上的文件,如下所示:
import my_library
@app.task()
def process_file(file):
result = my_library.process(file)
model = MyModel(result=result)
model.save()
return
def file_upload(request):
file = request.FILE['file']
version = parse_version(file)
process_file.run_async(file, queue=version)
Run Code Online (Sandbox Code Playgroud)
所以我的库的每个版本都有一个队列。我的想法是创建多个守护进程,每个守护进程对应我的库的每个队列/版本,使用虚拟环境来使用正确版本的 my_library。
但我不知道如何正确地做到这一点。
不同版本的 my_library 不能共存,因为它们包含依赖于具有相同版本号的自定义 C 库的 Cython 函数。
/etc/supervisor.d/celery.conf
[program:celery-version-1]
command = /path/to_venv_version_1/bin/python manage.py celery worker -Q version-1 ....
[program:celery-version-2]
command = /path/to_venv_version_2/bin/python manage.py celery worker -Q version-2 ....
[program:celery-version-3]
command = /path/to_venv_version_3/bin/python manage.py celery worker -Q version-3 ....
Run Code Online (Sandbox Code Playgroud)
然后分配你的任务:
def file_upload(request):
file = request.FILE['file']
version = parse_version(file)
process_file.run_async(file, queue=version)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1226 次 |
| 最近记录: |