Add Celery Support

This needs to be tested on a linux host - windows not supported
This commit is contained in:
Alexander Hosking 2021-12-13 15:21:44 -05:00
parent 7b2f789724
commit 20096010b4
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,5 @@
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)

23
api/api/celery.py Normal file
View File

@ -0,0 +1,23 @@
import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings')
app = Celery('api')
# Using a string here means the worker doesn't have to serialize
# the configuration object 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')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')

7
api/bills/tasks.py Normal file
View File

@ -0,0 +1,7 @@
### Celery Tasks!
from celery import shared_task
@shared_task
def get_overdue_bills():
return('This is a test')