Git Product home page Git Product logo

mbrsagor / djangocelery Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.18 MB

Asynchronous Tasks With Django and Celery. “Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.” For this post, we will focus on the scheduling feature to periodically run a job/task.

Python 87.67% Dockerfile 6.90% Shell 5.44%
celery celery-task django-celery-results

djangocelery's Introduction

Task scheduling

Setup

Dependencies

  • Python 3.10
  • postgres 13.2
  • Django 4.1

The following steps will walk you thru installation on a Mac. Linux should be similar. It's also possible to develop on a Windows machine, but I have not documented the steps. If you've developed the django apps run on Windows, you should have little problem getting up and running.

Please follow the instructions to run the project in your local dev server

git clone https://github.com/mbrsagor/djangoCelery.git
cd djangoCelery
virtualenv venv --python=python3.10
source venv/bin/activate
pip install -r requirements.txt
Then create .env file and paste code from sample.env file and add validate information.

|--> sample.env
|--> .env
Run the development server:
source venv/bin/activate
./manage.py migrate
./manage.py runserver

Install radis server

On Mac OS

brew install redis
brew services start redis

Brew permission errors? Try sudo chown -R "$USER":admin /usr/local Open & Test Redis: open terminal

redis-cli ping

Output: PONG

Then run redis server: redis-server alt text

Install Celery + Redis in your virtualenv.
pip install "celery[redis]"
pip install redis
pip install django-celery-beat
pip install django-celery-results
pip freeze > requirements.txt
Settings.py which install app added 2 third party app.
OTHER_APPS = [
    'django_celery_beat',
    'django_celery_results',
]

Then

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

Create celery.py to setup Celery app:

  • Navigate to root project config module (where settings and urls modules are)

  • Navigate to root project config module (where settings and urls modules are)

  • alt text

Then clone the project from git then the documentation follow. Hopefully, the project will run successfully. If any kind of errors please search google or youtube you will get very good result.

Migrate and create superuser

./manage.py makemigrations
./manage.py migrate
./manage.py createsuperuser
Run Celery Locally
  • Run the Celery Consumer Worker (locally). Make sure virtualenv is activated and this command where you run runserver*
  • First run a new terminal and follow the command celery -A CeleryTask worker -l info

  • Then open another terminal and run the command. celery -A CeleryTask beat -l info -S django

  • To see Celery Worker status
Here CeleryTask is a project name. If you develop same like app you may change there app name.

djangocelery's People

Contributors

dependabot[bot] avatar mbrsagor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.