Django Asynchronous Processing

前端 未结 2 1471
清歌不尽
清歌不尽 2021-02-03 12:47

I have a bunch of Django requests which executes some mathematical computations ( written in C and executed via a Cython module ) which may take an indeterminate amount ( on the

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-03 13:42

    Celery would be perfect for this.

    Since what you're doing is relatively simple (read: you don't need complex rules about how tasks should be routed), you could probably get away with using the Redis backend, which means you don't need to setup/configure RabbitMQ (which, in my experience, is more difficult).

    I use Redis with the most a dev build of Celery, and here are the relevant bits of my config:

    # Use redis as a queue
    BROKER_BACKEND = "kombu.transport.pyredis.Transport"
    BROKER_HOST = "localhost"
    BROKER_PORT = 6379
    BROKER_VHOST = "0"
    
    # Store results in redis
    CELERY_RESULT_BACKEND = "redis"
    REDIS_HOST = "localhost"
    REDIS_PORT = 6379
    REDIS_DB = "0"
    

    I'm also using django-celery, which makes the integration with Django happy.

    Comment if you need any more specific advice.

提交回复
热议问题