HSig
HSig

Reputation: 1

Flask appbuilder large application

I have built a "Large" application using Flask-AppBuilder and have 2 questions I have not seen the answer to.

  1. Is there any way to "split" a large application into multiple components (similar to what Blueprints do).
  2. My business logic has mostly ended up in the View's but... some of it does not feel right there. Few things I have added to the models, again does not feel right. This is logic that tends to create a long running processes so I have been testing out Celery.

Any examples of either of these would be lovely.

Upvotes: 0

Views: 478

Answers (1)

szeta
szeta

Reputation: 599

it does not really matter what framework you use, but as soon as the application grows you may want to isolate critical logic. Both for the reasons you described above, but also to be future-proof (you may want to move to a new frontend in the future without rewrite the heavy lifting).

I ususally set up a redis worker for this, and use e.g. flask only to trigger the queue with function calls. That also makes the application more scalable (concurrent users, more data) as you can simply start more workers listening to your queue if needed.

In essence:

from redis import Redis
from rq import Queue
from rq.job import Job

conn = Redis()
q = Queue(connection=conn)

Then as example in the flask routes (for appBuilder, use the views, or create your own lib) call:

result = q.enqueue('utils.your_function_name',args=(id,))

Have a look at RQ here for more examples, also how to monitor the status of your jobs etc.

https://python-rq.org/

Upvotes: 0

Related Questions