Skip to content

Commit b0c5500

Browse files
committed
Added Configuration & New Routes
1 parent 057baca commit b0c5500

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

core/settings.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
https://docs.djangoproject.com/en/3.2/ref/settings/
1111
"""
1212

13+
import os # <-- NEW: used by BASE_DIR definition
1314
from pathlib import Path
1415

1516
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -37,6 +38,8 @@
3738
'django.contrib.sessions',
3839
'django.contrib.messages',
3940
'django.contrib.staticfiles',
41+
'django_tm', # Django Tasks Manager # <-- NEW
42+
'django_celery_results', # Django Celery Results # <-- NEW
4043
]
4144

4245
MIDDLEWARE = [
@@ -51,10 +54,12 @@
5154

5255
ROOT_URLCONF = 'core.urls'
5356

57+
TEMPLATE_DIR_TASKS = os.path.join(BASE_DIR, "django_tm/templates") # <-- NEW
58+
5459
TEMPLATES = [
5560
{
5661
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57-
'DIRS': [],
62+
'DIRS': [TEMPLATE_DIR_TASKS], # <-- UPDATED
5863
'APP_DIRS': True,
5964
'OPTIONS': {
6065
'context_processors': [
@@ -123,3 +128,30 @@
123128
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
124129

125130
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
131+
132+
#############################################################
133+
# Django & Celery configurations
134+
#
135+
# BASE_DIR points to the ROOT of the project
136+
# Note: make sure you have 'os' object imported
137+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
138+
139+
# Working Directories required write permission
140+
CELERY_SCRIPTS_DIR = os.path.join(BASE_DIR, "celery_scripts" )
141+
CELERY_LOGS_DIR = os.path.join(BASE_DIR, "celery_logs" )
142+
143+
CELERY_BROKER_URL = os.environ.get("CELERY_BROKER", "redis://localhost:6379")
144+
CELERY_RESULT_BACKEND = os.environ.get("CELERY_BROKER", "redis://localhost:6379")
145+
146+
CELERY_TASK_TRACK_STARTED = True
147+
CELERY_TASK_TIME_LIMIT = 30 * 60
148+
CELERY_CACHE_BACKEND = "django-cache"
149+
CELERY_RESULT_BACKEND = "django-db"
150+
CELERY_RESULT_EXTENDED = True
151+
CELERY_RESULT_EXPIRES = 60*60*24*30 # Results expire after 1 month
152+
CELERY_ACCEPT_CONTENT = ["json"]
153+
CELERY_TASK_SERIALIZER = 'json'
154+
CELERY_RESULT_SERIALIZER = 'json'
155+
156+
#############################################################
157+
#############################################################

core/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.contrib import admin
17-
from django.urls import path
17+
from django.urls import path, include # <-- UPDATED: Added 'include' HELPER
1818

1919
urlpatterns = [
2020
path('admin/', admin.site.urls),
21+
path("", include("django_tm.urls")), # <-- NEW
2122
]

0 commit comments

Comments
 (0)