Yassine Belmamoun
Yassine Belmamoun

Reputation: 420

Back end tasks and frontend separation

I use Django and Django Rest Framework for my internal API and I use Vue.js for my frontend. The backend (API) and the frontend are totally separated.

I need to run a background task (every time a user is created) and I am considering 2 solutions:

  1. Call (with a post_save signal) a function that runs the task.

Note that this function will call a 3rd party API. The call might fail for various reasons and/or run during a long period ~20sec.

  1. Create a background task

With Redis or RabbitMQ or django-background-tasks.

Which solution should I go for ? If both solutions are acceptable, what would be the limitations/advantages of each one ?

Upvotes: 0

Views: 334

Answers (1)

reon
reon

Reputation: 106

You might need django celery. This is a great package for background tasks for django, you can choose either Redis or RabbitMQ as the broker, where the brokers doesn't matter much on my opinion.

Why can this be a good solution for your problem?

  1. This is easy to install where you just need to install the django celery and redis(I prefer redis), configure some settings and you have now async functions.
  2. You might need soon a scheduled task, where you just need to install its additional package.
  3. You only need to build type function and attach a decorator for it to be async.

from celery import shared_task @shared_task def add(x,y): return X+y

and call it anywhere in you code

add.delay()

you know how background task.

Upvotes: 0

Related Questions