How to start a long-running process from a Django view?

前端 未结 4 437
予麋鹿
予麋鹿 2020-12-13 21:18

I need to run a process that might take hours to complete from a Django view. I don\'t need to know the state or communicate with it but I need that view to redirect away ri

相关标签:
4条回答
  • 2020-12-13 21:32

    First of all - try to using cron for you task, as early say shanyu.

    If it doesn't suit you - then try to use CeleryProject, for task Queue for Django. For working it uses RabbitMQ. And here is a little overview for simple using of basing futures

    0 讨论(0)
  • 2020-12-13 21:37

    Take a look at the code in kronos.py to see one solution to this problem.

    http://www.razorvine.net/download/kronos.py

    0 讨论(0)
  • 2020-12-13 21:42

    I don't know if this will be suitable for your case, nevertheless here is what I do: I use a task queue (via a django model); when the view is called, it enters a new record in the tasks and redirects happily. Tasks in turn are executed by cron on a regular basis independently from django.

    Edit: cron calls the relevant (and custom) django command to execute the task.

    0 讨论(0)
  • 2020-12-13 21:42

    http://code.google.com/p/django-command-extensions/wiki/JobsScheduling

    Is a nice library that that you can use to accomplish this task.

    0 讨论(0)
提交回复
热议问题