Install Celery

This commit is contained in:
Jonas 12t 2021-11-03 17:24:56 +04:00
parent d18bd817fd
commit b5870cf12d
11 changed files with 103 additions and 23 deletions

View File

@ -0,0 +1,8 @@
# Create your tasks here
from celery import shared_task
@shared_task
def add(x, y):
return x + y

View File

@ -7,19 +7,11 @@ from django.utils import timezone
from ApiBillet.thread_mailer import ThreadMaileur from ApiBillet.thread_mailer import ThreadMaileur
from BaseBillet.models import Reservation, LigneArticle, Ticket, Product, Configuration, Paiement_stripe from BaseBillet.models import Reservation, LigneArticle, Ticket, Product, Configuration, Paiement_stripe
import logging
from TiBillet import settings from TiBillet import settings
import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.info(f'import basebillet.signals')
# @receiver(post_save, sender=Reservation)
# def trigger_reservation(sender, instance: Reservation, created, **kwargs):
# if instance.status == Reservation.PAID:
######################################################################## ########################################################################

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',)

View File

@ -0,0 +1,49 @@
'''
import os
from celery import Celery
# setting the Django settings module.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TiBillet.settings')
app = Celery('TiBillet')
app.config_from_object('django.conf:settings', namespace='CELERY')
# Looks up for task modules in Django applications and loads them
app.autodiscover_tasks()
'''
'''
celery -A TiBillet worker -l INFO
from TiBillet.celery import my_task
my_task.delay()
'''
import os
from django.db import connection
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TiBillet.settings')
from django.conf import settings
from tenant_schemas_celery.app import CeleryApp as TenantAwareCeleryApp
app = TenantAwareCeleryApp()
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request}')
@app.task
def add(x, y):
return x + y
@app.task
def my_task():
print(connection.schema_name)

View File

@ -212,6 +212,15 @@ EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', False) EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', False)
EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', True) EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', True)
# Celery Configuration Options
CELERY_TIMEZONE=os.environ.get('TIME_ZONE', 'UTC')
CELERY_TASK_TRACK_STARTED=True
CELERY_TASK_TIME_LIMIT=30 * 60
BROKER_URL=os.environ.get('CELERY_BROKER')
# CELERY_BROKER=os.environ.get('CELERY_BROKER')
# CELERY_BROKER_URL=os.environ.get('CELERY_BROKER')
# DJANGO_CELERY_BEAT_TZ_AWARE=False
# celery -A TiBillet worker -l INFO
# Jet Menu # Jet Menu
# -------------------------------------/ # -------------------------------------/

View File

@ -39,7 +39,6 @@ urlpatterns = [
re_path(r'api/', include('ApiBillet.urls')), re_path(r'api/', include('ApiBillet.urls')),
re_path(r'qr/', include('QrcodeCashless.urls')), re_path(r'qr/', include('QrcodeCashless.urls')),
# pour carte GEN1 Bisik # pour carte GEN1 Bisik
re_path(r'(?P<numero_carte>^\w{5}$)', include('QrcodeCashless.urls')), re_path(r'(?P<numero_carte>^\w{5}$)', include('QrcodeCashless.urls')),

View File

@ -1 +1,3 @@
sleep 30d sleep 30d
# celery -A TiBillet worker -l INFO

1
DjangoFiles/launch_celery.sh Executable file
View File

@ -0,0 +1 @@
celery -A TiBillet worker -l INFO

View File

@ -14,6 +14,11 @@ services:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB} POSTGRES_DB: ${POSTGRES_DB}
redis:
image: redis:6-alpine
restart: always
container_name: redis
hostname: redis
tibillet_django: tibillet_django:
container_name: tibillet_django container_name: tibillet_django
@ -30,3 +35,17 @@ services:
command: "bash /DjangoFiles/launch.sh" command: "bash /DjangoFiles/launch.sh"
depends_on: depends_on:
- tibillet_postgres - tibillet_postgres
- redis
tibillet_celery:
container_name: tibillet_celery
build: ../Dockerfile/
restart: always
env_file: .env
volumes:
- "../../DjangoFiles:/DjangoFiles"
- "../../Docker/bashrc:/root/.bashrc"
working_dir: /DjangoFiles
command: "bash /DjangoFiles/launch.sh"
depends_on:
- tibillet_django

View File

@ -6,6 +6,9 @@ POSTGRES_USER='tibillet_postgres_user'
POSTGRES_PASSWORD='tibillet_postgres_password' POSTGRES_PASSWORD='tibillet_postgres_password'
POSTGRES_DB='tibillet' POSTGRES_DB='tibillet'
CELERY_BROKER='redis://redis:6379/0'
CELERY_BACKEND='redis://redis:6379/0'
DEBUG_DJANGO=True DEBUG_DJANGO=True
TIME_ZONE='Indian/Reunion' TIME_ZONE='Indian/Reunion'

View File

@ -63,27 +63,20 @@ RUN pip install django-stdimage
RUN pip install stripe RUN pip install stripe
# RUN apt-get install -y fonts-font-awesome
# RUN apt-get install -y libffi-dev
# RUN apt-get install -y libgdk-pixbuf2.0-0
# RUN apt-get install -y libpango1.0-0
# RUN apt-get install -y python-dev
# RUN apt-get install -y python-lxml
# RUN apt-get install -y shared-mime-info
# RUN apt-get install -y libcairo2
RUN apt install -y python3-cffi RUN apt install -y python3-cffi
RUN apt install -y python3-brotli RUN apt install -y python3-brotli
RUN apt install -y libpango-1.0-0 RUN apt install -y libpango-1.0-0
RUN apt install -y libpangoft2-1.0-0 RUN apt install -y libpangoft2-1.0-0
RUN pip install django-weasyprint RUN pip install django-weasyprint
RUN pip install celery
RUN pip install redis
RUN pip install tenant-schemas-celery
RUN apt-get -y clean RUN apt-get -y clean
RUN python --version RUN python --version
RUN django-admin --version RUN django-admin --version
RUN pip freeze RUN pip freeze
RUN weasyprint --version
RUN pip freeze | grep weasyprint