|
Sakib Raza Oodles

Sakib Raza (Backend-Senior Associate Consultant L1 - Development)

Experience:2+ yrs

Sakib is an experienced Backend Developer with expertise in Python technology, including Django and MySQL. He has a deep understanding of the latest technologies and has experience in API implementation, web services, development testing, and code enhancement. Sakib has contributed significantly to the company's values through his deliverables in client projects such as myhelpa, FarmQ, optaplanner POC and Nowcast AI.

Sakib Raza Oodles
Sakib Raza
(Senior Associate Consultant L1 - Development)

Sakib is an experienced Backend Developer with expertise in Python technology, including Django and MySQL. He has a deep understanding of the latest technologies and has experience in API implementation, web services, development testing, and code enhancement. Sakib has contributed significantly to the company's values through his deliverables in client projects such as myhelpa, FarmQ, optaplanner POC and Nowcast AI.

LanguageLanguages

DotEnglish

Fluent

Skills
Skills

DotMySQL

80%

DotHTML, CSS

40%

DotNo SQL/Mongo DB

80%

DotPostgres

80%

DotPython

80%

DotJavascript

40%

DotDjango

80%
ExpWork Experience / Trainings / Internship

May 2022-Present

Python/Django Developer

Gurgaon


Oodles Technologies

Gurgaon

May 2022-Present

EducationEducation

2018-2022

Dot

J.C. Bose University of Science and Technology

B.Tech-Computer Software Engineer

Top Blog Posts
Assigning Tasks Using Celery In Django

Why Use Celery?

1. Offloading running task

2. Sending bulk emails

3. Periodic task

4. Background task

5. Task routing

 

 

First of all, you have to install Celery using the following commands:

- -  pip install celery

- - pip install django-celery-beat

Note: Make sure you have already installed Django

 

Also, Read Tenant Schema In Python Django

 

After that below changes add  'celery' in installed apps in the Django setings.py file

 

- - 'celery'  in installed apps

- - CELERY_BROKER_URL = 'redis://localhost:6379/0'

- - CELERY_RESULT_BACKEND = 'django-db'

- - CELERY_CACHE_BACKEND = 'django-cache'

Also, you have to install redis: pip install django-redis  

 

 

After that, you have to add changes in __init__.py file of root directory.

 

__init__.py changes : 

We will need to import Celery and create an instance of the Celery class. We will also need to set the Django settings module as an environment variable so that Celery knows how to connect to our Django project.
Next, we will need to define our tasks in the celery.py file from .celery import app as celery_app

__all__ = ('celery_app',)

 

 

And also you've to create celery.py in the root directory

 

Create a Celery instance in the root directory:

 

celery.py changes:-

 

import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_name.settings')
app = Celery('Project_name', broker_connection_retry_on_startup=True)
app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

Note:  broker_connection_retry_on_startup=True this change is required in celery new version

 

 

Also, Read Django vs Flask: Neck To Neck Comparison

 

 

For running tasks in the background:

Define tasks in one or more Django app modules. In the application directory, create a file called tasks.py.
This is where we will define our Celery tasks and define our tasks using the @shared_task decorator, but it’s a good idea to create a separate app for them.

 

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

And for running tasks in background, you have to call a function with .delay like the below method

from myapp.tasks import add
result = add.delay(2, 3)

 

And for scheduling tasks for a particular time or periodic tasks -:

 

Define the function as per your need.

@shared_task()
def add(x, y)
  return x+y

 

and add these changes in the settings.py file
 
CELERY_BEAT_SCHEDULE = {
    'background_task': {
        'task': 'core.auto_gpt_on.auto_gpt_on',
        'schedule': crontab(hour=12, minute=0),  # Schedule at 12:00 PM
    },
}

 

 

And after that run these commands for the scheduled task - :

 

Cmd for celery worker - 'celery -A project_name worker -l INFO'
Cmd for celery beat - 'celery -A project_name beat -l INFO'   # if using the periodic task feature

 

After that, your task is scheduled for a specific time period. 
Banner

Don't just hire talent,
But build your dream team

Our experience in providing the best talents in accordance with diverse industry demands sets us apart from the rest. Hire a dedicated team of experts to build & scale your project, achieve delivery excellence, and maximize your returns. Rest assured, we will help you start and launch your project, your way – with full trust and transparency!