celery setup finished
rodzic
9c3b9dcefa
commit
b45b2f60cf
|
@ -1,3 +1,3 @@
|
||||||
from .celery import app as celery_app
|
from .celery import app as celery_app
|
||||||
|
|
||||||
__all__ = ('celery_app',)
|
__all__ = ('celery_app',)
|
|
@ -3,7 +3,7 @@ import os
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
|
|
||||||
# Set the default Django settings module for the 'celery' program.
|
# Set the default Django settings module for the 'celery' program.
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'artel.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'artel.settings.production')
|
||||||
|
|
||||||
app = Celery('artel')
|
app = Celery('artel')
|
||||||
|
|
||||||
|
@ -15,3 +15,8 @@ app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||||
|
|
||||||
# Load task modules from all registered Django apps.
|
# Load task modules from all registered Django apps.
|
||||||
app.autodiscover_tasks()
|
app.autodiscover_tasks()
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True)
|
||||||
|
def debug_task(self):
|
||||||
|
print(f'Request: {self.request!r}')
|
||||||
|
|
|
@ -51,6 +51,8 @@ INSTALLED_APPS = [
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"rest_framework",
|
"rest_framework",
|
||||||
"phonenumber_field",
|
"phonenumber_field",
|
||||||
|
"django_celery_results",
|
||||||
|
"django_celery_beat"
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -187,4 +189,11 @@ EMAIL_PORT = os.environ.get('EMAIL_PORT', 587)
|
||||||
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'mtyton@tepewu.pl')
|
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'mtyton@tepewu.pl')
|
||||||
|
|
||||||
# CELERY settings
|
# CELERY settings
|
||||||
CELERY_BROKER_URL = 'amqp://user:**@rabbit1:5672//:'
|
CELERY_RESULT_BACKEND = 'django-db'
|
||||||
|
CELERY_CACHE_BACKEND = 'django-cache'
|
||||||
|
CELERY_TIMEZONE = "YourTimeZone"
|
||||||
|
CELERY_TASK_TRACK_STARTED = True
|
||||||
|
CELERY_TASK_TIME_LIMIT = 30 * 60
|
||||||
|
# CELERY_RESULT_BACKEND_DB = f'db+mysql+pymysql://{os.environ.get("MYSQL_USER")}:{os.environ.get("MYSQL_PASSWORD")}@db/{os.environ.get("MYSQL_DATABASE")}'
|
||||||
|
CELERY_BROKER_URL = f'amqp://{os.environ.get("RABBITMQ_DEFAULT_USER")}:{os.environ.get("RABBITMQ_DEFAULT_PASS")}@rabbit//'
|
||||||
|
CELERY_TASK_RESULT_EXPIRES = 18000
|
||||||
|
|
|
@ -1,5 +1,29 @@
|
||||||
version: "3.8"
|
version: "3.8"
|
||||||
services:
|
services:
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- POSTGRES_ROOT_PASSWORD
|
||||||
|
- POSTGRES_USER
|
||||||
|
- POSTGRES_PASSWORD
|
||||||
|
- POSTGRES_DB
|
||||||
|
volumes:
|
||||||
|
- ../postgres/:/var/lib/postgresql
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
|
||||||
|
rabbit:
|
||||||
|
hostname: rabbit
|
||||||
|
image: rabbitmq:3.6.0
|
||||||
|
environment:
|
||||||
|
- RABBITMQ_DEFAULT_USER
|
||||||
|
- RABBITMQ_DEFAULT_PASS
|
||||||
|
ports:
|
||||||
|
- "5672:5672" # We forward this port because it's useful for debugging
|
||||||
|
- "15672:15672" # Here, we can access RabbitMQ management plugin
|
||||||
|
|
||||||
comfy:
|
comfy:
|
||||||
build:
|
build:
|
||||||
dockerfile: Dockerfile.local
|
dockerfile: Dockerfile.local
|
||||||
|
@ -15,15 +39,39 @@ services:
|
||||||
- .env
|
- .env
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
tty: true
|
tty: true
|
||||||
db:
|
|
||||||
image: postgres
|
beat:
|
||||||
restart: always
|
build:
|
||||||
environment:
|
context: .
|
||||||
- POSTGRES_ROOT_PASSWORD
|
dockerfile: Dockerfile
|
||||||
- POSTGRES_USER
|
command: celery -A artel beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
|
||||||
- POSTGRES_PASSWORD
|
|
||||||
- POSTGRES_DB
|
|
||||||
volumes:
|
volumes:
|
||||||
- ../postgres/:/var/lib/postgresql
|
- ./:/app
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
environment:
|
||||||
|
- SECRET_KEY
|
||||||
|
- DATABASE_URL
|
||||||
|
depends_on:
|
||||||
|
- comfy
|
||||||
|
- rabbit
|
||||||
|
|
||||||
|
worker:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
command: celery -A artel worker -l info
|
||||||
|
volumes:
|
||||||
|
- ./:/app
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
- SECRET_KEY
|
||||||
|
- DATABASE_URL
|
||||||
|
depends_on:
|
||||||
|
- comfy
|
||||||
|
- rabbit
|
||||||
|
- beat
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
rabbitmq_data:
|
|
@ -10,4 +10,4 @@ factory-boy==3.2.1
|
||||||
pdfkit==1.0.0
|
pdfkit==1.0.0
|
||||||
celery==5.3.1
|
celery==5.3.1
|
||||||
django-celery-beat==2.5.0
|
django-celery-beat==2.5.0
|
||||||
celery[librabbitmq]==5.3.1
|
django-celery-results==2.5.1
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
rabbitmq3:
|
|
||||||
container_name: "rabbitmq"
|
|
||||||
image: rabbitmq:3.8-management-alpine
|
|
||||||
environment:
|
|
||||||
- RABBITMQ_DEFAULT_USER=myuser
|
|
||||||
- RABBITMQ_DEFAULT_PASS=mypassword
|
|
||||||
ports:
|
|
||||||
# AMQP protocol port
|
|
||||||
- "5672:5672"
|
|
||||||
# HTTP management UI
|
|
||||||
- "15672:15672"
|
|
||||||
celery-worker:
|
|
||||||
build:
|
|
||||||
dockerfile: Dockerfile.local
|
|
||||||
context: ./
|
|
||||||
volumes:
|
|
||||||
- ./:/app
|
|
||||||
environment:
|
|
||||||
- SECRET_KEY
|
|
||||||
- DATABASE_URL
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
command: celery -A artel.celery:app worker
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
- rabbitmq3
|
|
||||||
stdin_open: true
|
|
||||||
tty: true
|
|
Ładowanie…
Reference in New Issue