-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
from __future__ import absolute_import | ||
from .celery import app as celery_app | ||
# This will make sure the Celery app is always imported when | ||
# Django starts so that @shared_task decorator will use this app. | ||
from .celery import app as celery_app | ||
|
||
__all__ = ('celery_app',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
# Refer Here : https://realpython.com/asynchronous-tasks-with-django-and-celery/ | ||
# Refer Here : https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html | ||
|
||
from __future__ import absolute_import | ||
import os | ||
|
||
from celery import Celery | ||
from django.conf import settings | ||
from celery.schedules import crontab | ||
|
||
# Set the default Django settings module for the 'celery' program. | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AlumniConnect.settings.development') | ||
|
||
app = Celery('AlumniConnect') | ||
|
||
# Using a string here means the worker doesn't have to serialize | ||
# the configuration object to child processes (no need to convert | ||
# configuration object to byte stream since it can just pass the | ||
# `django.conf:settings` string to child processes). | ||
# - namespace='CELERY' means all celery-related configuration keys | ||
# should have a `CELERY_` prefix. | ||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AlumniConnect.settings.production') | ||
app = Celery("AlumniConnect") | ||
# Load task modules from all registered Django apps. | ||
app.autodiscover_tasks() | ||
|
||
app.config_from_object("django.conf:settings") | ||
app.autodiscover_tasks(lambda : settings.INSTALLED_APPS) | ||
app.conf.beat_schedule = { | ||
'send-birthday-wishes': { | ||
'task': 'applications.alumniprofile.tasks.send_birthday_wishes', | ||
'schedule': crontab(hour=13, minute=5), | ||
}, | ||
} | ||
|
||
@app.task(bind=True) | ||
def debug_task(self): | ||
print('Request: {0!r}'.format(self.request)) | ||
print(f'Request: {self.request!r}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters