diff --git a/api/api/__init__.py b/api/api/__init__.py index e69de29..1e3599b 100644 --- a/api/api/__init__.py +++ b/api/api/__init__.py @@ -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',) \ No newline at end of file diff --git a/api/api/celery.py b/api/api/celery.py new file mode 100644 index 0000000..79b9c4c --- /dev/null +++ b/api/api/celery.py @@ -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}') \ No newline at end of file diff --git a/api/bills/tasks.py b/api/bills/tasks.py new file mode 100644 index 0000000..b11b48f --- /dev/null +++ b/api/bills/tasks.py @@ -0,0 +1,7 @@ +### Celery Tasks! + +from celery import shared_task + +@shared_task +def get_overdue_bills(): + return('This is a test') \ No newline at end of file