1

I am already thinking for few days what the best way to do it.

I am selling an item I am manufacturing however the item I am selling can be composed from other items and those other items can be composed from other items and so on.

After the sale order is created I want to trigger process creating internal sales orders of all the items required to build this item so it should be some kind of recursion .

Final items that cannot be produced have a flag is_production=False so i know i dont have to go deeper

For this I was thinking to create a method in view.py that will be triggered by confirmation of my Sales order. But I afraid that since i can not predict complexity of product manufactured it will take forever and will be costly for performance . As well there is a risk of never ending loops. so may be doing it in the view is not a great idea and I am thinking on alternative and by investigation I did it should be implemented with something like django-celery

Question since I never used django celery before and I want to confirm my understanding: Is django-celery is the best and only option to solve my requirement?

Ilya Bibik
  • 3,924
  • 4
  • 23
  • 48
  • 1
    You can use Django RQ which is Redis-based and much simpler to configure http://stackoverflow.com/questions/38106696/django-rq-how-to-call-function/38106908#38106908 http://python-rq.org/patterns/django/ – dmitryro Jul 05 '16 at 19:49
  • But Redis is DB and asynchronous task queue/job queue? – Ilya Bibik Jul 05 '16 at 20:05
  • Redis is lightweight and it also can, and should, be used as cache engine for Django. Once you start using it you'll find it extremely helpful. It's coded in C, so it's uberfast. – dmitryro Jul 05 '16 at 20:07
  • Actually Redis is a key/value storage with tons of different features – dmitryro Jul 05 '16 at 20:08
  • To use python's wrapper https://github.com/andymccurdy/redis-py – dmitryro Jul 05 '16 at 20:11

1 Answers1

1

First, about the application design issue: as you said, "doing it in the view is not a great idea"... in general you must avoid running processes that require much time on the request-response cycle, this is bad for the UX and could end in the request being aborted because a timeout on some layer (think in database transaction timeout, application container timeout, reverse proxy timeout, etc).

My recommendation: use something (Celery or any other solution) to off-load the process that creates internal sales orders, and any other long-running process (like sending emails).

Second: which framework to use? There are so many options... you'll need to research that :-)

Third: never ending loops. You'll have to fix that, regardeless of the design to use.

hgdeoro
  • 1,030
  • 10
  • 7