{"id":24989135,"url":"https://github.com/engineervix/django-celery-sample","last_synced_at":"2025-04-12T00:20:51.498Z","repository":{"id":45254348,"uuid":"341721875","full_name":"engineervix/django-celery-sample","owner":"engineervix","description":"A simple Django project to illustrate the use of Celery","archived":false,"fork":false,"pushed_at":"2025-04-03T17:50:25.000Z","size":602,"stargazers_count":1,"open_issues_count":14,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T18:37:22.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/engineervix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-23T23:41:55.000Z","updated_at":"2022-10-13T12:40:14.000Z","dependencies_parsed_at":"2023-01-22T19:30:12.381Z","dependency_job_id":"35f42d72-c18d-4f88-b19c-a1f1cf874c08","html_url":"https://github.com/engineervix/django-celery-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineervix%2Fdjango-celery-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineervix%2Fdjango-celery-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineervix%2Fdjango-celery-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineervix%2Fdjango-celery-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/engineervix","download_url":"https://codeload.github.com/engineervix/django-celery-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248498084,"owners_count":21114034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-04T12:18:43.936Z","updated_at":"2025-04-12T00:20:51.465Z","avatar_url":"https://github.com/engineervix.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A simple Django project to illustrate the use of Celery\n\n\u003e I created this project to accompany my blog post at \u003chttps://importthis.tech/djangocelery-from-development-to-production\u003e\n\n[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)\n\n[![CircleCI](https://circleci.com/gh/engineervix/django-celery-sample.svg?style=svg)](https://circleci.com/gh/engineervix/django-celery-sample)\n[![codecov](https://codecov.io/gh/engineervix/django-celery-sample/branch/master/graph/badge.svg?token=SFRBRZB8BJ)](https://codecov.io/gh/engineervix/django-celery-sample)\n\n[![python3](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-brightgreen.svg)](https://python3statement.org/#sections50-why)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![code style: prettier](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Conventional Changelog](https://img.shields.io/badge/changelog-conventional-brightgreen.svg)](http://conventional-changelog.github.io)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Prerequisites](#prerequisites)\n- [Project Setup](#project-setup)\n- [Run the project](#run-the-project)\n  - [without celery](#without-celery)\n  - [with celery](#with-celery)\n- [Tests](#tests)\n- [Production-ready](#production-ready)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Prerequisites\n\n- A [\\*nix](https://en.wikipedia.org/wiki/Unix-like) environment.\n- [Python 3.6+](https://www.python.org/). I use [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/) for managing python virtual environments.\n- [Node.js 12+](https://nodejs.org/) with the following packages installed **globally** (depending on your Node.js setup, you might need to install as superuser):\n  - [gulp](https://gulpjs.com/) – `npm install -g gulp-cli`\n  - [concurrently](https://github.com/kimmobrunfeldt/concurrently): `npm install -g concurrently`\n  - [MailDev](https://github.com/maildev/maildev) – `npm install -g maildev`\n  - [Sass](https://sass-lang.com): `npm install -g sass`\n  - [prettier](https://github.com/prettier/prettier/): `npm install prettier -g`\n  - [Browsersync](https://browsersync.io/): `npm install -g browser-sync`\n  - [commitizen](https://github.com/commitizen/cz-cli) – `npm install -g commitizen`\n  - [DocToc](https://github.com/thlorenz/doctoc): `npm install -g doctoc`\n- [yarn](https://yarnpkg.com/): See [installation instructions for your platform](https://classic.yarnpkg.com/en/docs/install#debian-stable).\n- [redis](https://redis.io/) must be installed and configured on your development machine.\n\n## Project Setup\n\nFirst, clone the project and `cd` into the cloned directory:\n\n```sh\ngit clone https://github.com/engineervix/django-celery-sample.git\ncd django-celery-sample\n```\n\nThen, assuming that you have created and activated your virtual environment, install the python dependencies. This project uses [pip-tools](https://github.com/jazzband/pip-tools) to manage python dependencies.\n\n```sh\npip install pip-tools \u0026\u0026 pip-sync\n# or you could just `pip install -r requirements.txt`\n```\n\nInstall the Node.js dependencies and copy the vendor libraries to the `static` directory:\n\n```sh\nyarn install \u0026\u0026 gulp cp\n```\n\nCreate a postgres database and user for the project. If you are using tools such as [PGAdmin](https://www.pgadmin.org/) or [Postgres.app](https://postgresapp.com/), you please feel free to use them according to their documentation. If you are using the CLI like me, you could do it as follows:\n\n```sh\n# assuming your DATABASE is my_DB\n# assuming USER is my_user\n# assuming your PASSWORD is my_password\npsql -c \"CREATE USER my_user PASSWORD 'my_password'\" \\\n\u0026\u0026 psql -c \"CREATE DATABASE my_DB OWNER my_user\" \\\n\u0026\u0026 psql -c \"GRANT ALL PRIVILEGES ON DATABASE my_DB TO my_user\"\n```\n\n\u003e In order to simplify this, I wrote a simple `bash` script which provides a command `create_db`, and placed it in my `$PATH`. It prompts me for the database and the user names, and generates a random password. I should probably add it to this repo as a utility.\n\nNow that your database is set up, it's time to set up your environment variables. This repo contains a direcctory `.envs.sample` which has sample `.env` files for you to build on and customize.\n\n```sh\n# first, rename the `.envs.sample` directory to `.envs` \nmv -v .envs.sample/ .envs/\n\n# then, let's remove the .sample suffix from all the `*.env.sample` files in the renamed directory\nfor i in $(ls -a .envs/ | grep sample);do mv -i .envs.sample/$i .envs.sample/`basename $i .sample`; done\n```\n\nThere are three `.env` files:\n\n1. `.dev.env` – for the **development** environment\n2. `.test.env` – for the **test** environment\n3. `.prod.env` – for the **production** environment\n\nEdit those files and update the environment variables accordingly. The table below shows the environment variables that need to be updated. For now, you can skip the environment variables for production, and only update them when you are ready to go into production.\n\nPlease note that, in production, this project uses\n\n- [Sendgrid](https://sendgrid.com/) for sending emails via [django-anymail](https://github.com/anymail/django-anymail). You can use your preferred provider and update both the [production settings](config/settings/production.py) and environment variables accordingly.\n- [Sentry](https://sentry.io) for error tracking. You'll have to setup an account (if you don't have one already) and register the project.\n\n|   | development       | test              | production         |\n|---|-------------------|-------------------|--------------------|\n| 1 | DJANGO_SECRET_KEY | DJANGO_SECRET_KEY | DJANGO_SECRET_KEY  |\n| 2 | DATABASE_URL      |                   | DATABASE_URL       |\n| 3 |                   |                   | EMAIL_RECIPIENTS   |\n| 4 |                   |                   | DEFAULT_FROM_EMAIL |\n| 5 |                   |                   | ALLOWED_HOSTS      |\n| 6 |                   |                   | BASE_URL           |\n| 7 |                   |                   | SENDGRID_API_KEY   |\n| 8 |                   |                   | SENTRY_DSN         |\n\nOkay, now that you have installed all dependencies and have set up your database and environment variables, you can now make migrations and create the superuser in readiness to run the project.\n\n```sh\n./manage.py makemigrations \u0026\u0026 ./manage.py migrate\n./manage.py createsuperuser\n```\n\nWe are now ready to run!\n\n## Run the project\n\n### without celery\n\n```sh\nyarn dev\n```\n\n### with celery\n\n```sh\nyarn dev:celery\n```\n\nIf all goes well, this will launch two tabs in your default browser – a `maildev` tab and a `django` tab with today's date and a quote for today, as shown in the screenshot below:\n\n![screenshot](https://i.imgur.com/Oey9js2.png)\n\nThe [Browsersync](https://browsersync.io/) and [gulp](https://gulpjs.com/) setup provides for automatic restarting of the dev server and autoreload of the browser, so you can work on the project and make changes to the files without having to do this manually.\n\n## Tests\n\nThis project uses pytest and the initial tests should give you about 93% test coverage.\n\n```sh\nyarn test\n```\n\n## Production-ready\n\nGoing into production shouldn't be too complicated, as the project includes production-ready configurations right from the start:\n\n- I have already mentioned the [`.prod.env`](.envs.sample/.prod.env.sample) file,\n- There's the [`config/settings/production.py`](config/settings/production.py) file,\n- I created a separate [`wsgi_production.py`](config/wsgi_production.py) file and\n- There are some celery and celery beat configuration files in the [`.envs.example/celery`](.envs.sample/celery/) directory. These will come in handy if you're using [systemd](https://systemd.io/). I wrote a [blog post](https://importthis.tech/djangocelery-from-development-to-production) that describes how to daemonize celery and celery beat using systemd.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineervix%2Fdjango-celery-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fengineervix%2Fdjango-celery-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineervix%2Fdjango-celery-sample/lists"}