diff --git a/.dockerignore b/.dockerignore index e911b91..8032263 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,5 @@ Dockerfile README.md db.sqlite3 +docker-compose.yml env diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f0cdc6b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +--- + +services: + broker: + container_name: shiftregister_broker + image: rabbitmq:3-alpine + restart: unless-stopped + ports: + - 127.0.0.1:5672:5672 + + result_backend: + container_name: shiftregister_result_backend + image: redis:6-alpine + restart: unless-stopped + ports: + - 127.0.0.1:6379:6379 diff --git a/requirements.txt b/requirements.txt index 7bc49f3..71131e0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,24 @@ +amqp==5.1.1 asgiref==3.5.0 +async-timeout==4.0.2 +billiard==3.6.4.0 +celery==5.2.6 +click==8.1.2 +click-didyoumean==0.3.0 +click-plugins==1.1.1 +click-repl==0.2.0 +Deprecated==1.2.13 Django==4.0.4 +kombu==5.2.4 +librabbitmq==2.0.0 +packaging==21.3 +prompt-toolkit==3.0.29 psycopg2-binary==2.9.3 +pyparsing==3.0.8 +pytz==2022.1 +redis==4.2.2 +six==1.16.0 sqlparse==0.4.2 +vine==5.0.0 +wcwidth==0.2.5 +wrapt==1.14.0 diff --git a/shiftregister/__init__.py b/shiftregister/__init__.py index e69de29..53f4ccb 100644 --- a/shiftregister/__init__.py +++ b/shiftregister/__init__.py @@ -0,0 +1,3 @@ +from .celery import app as celery_app + +__all__ = ("celery_app",) diff --git a/shiftregister/app/tasks.py b/shiftregister/app/tasks.py new file mode 100644 index 0000000..b368d1d --- /dev/null +++ b/shiftregister/app/tasks.py @@ -0,0 +1,5 @@ +from celery import shared_task + +@shared_task +def test(): + return 'Hello, Celery!' diff --git a/shiftregister/celery.py b/shiftregister/celery.py new file mode 100644 index 0000000..7e3f1d1 --- /dev/null +++ b/shiftregister/celery.py @@ -0,0 +1,11 @@ +import os + +from celery import Celery + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shiftregister.settings") + +app = Celery("shiftregister") + +app.config_from_object("django.conf:settings", namespace='CELERY') + +app.autodiscover_tasks() diff --git a/shiftregister/settings.py b/shiftregister/settings.py index 44405cf..acc3930 100644 --- a/shiftregister/settings.py +++ b/shiftregister/settings.py @@ -137,3 +137,7 @@ STATICFILES_DIRS = [ # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +CELERY_BROKER_URL = getenv("CELERY_BROKER_URL", "amqp://guest:guest@localhost:5672//") + +CELERY_RESULT_BACKEND = getenv("CELERY_RESULT_BACKEND", "redis://")