mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-25 10:08:36 +02:00
build: replace celery with procrastinate
This commit is contained in:
18
.env.example
18
.env.example
@@ -1,10 +1,7 @@
|
|||||||
COMPOSE_FILE=
|
COMPOSE_FILE=
|
||||||
SERVER_NAME=
|
SERVER_NAME=
|
||||||
DB_NAME=
|
DB_NAME=
|
||||||
REDIS_NAME=
|
PROCRASTINATE_NAME=
|
||||||
CELERYWORKER_NAME=
|
|
||||||
CELERYBEAT_NAME=
|
|
||||||
FLOWER_NAME=
|
|
||||||
|
|
||||||
DEBUG=true
|
DEBUG=true
|
||||||
URL = https://mais.alcanceconsulting.com.br
|
URL = https://mais.alcanceconsulting.com.br
|
||||||
@@ -20,24 +17,11 @@ SQL_PASSWORD=
|
|||||||
SQL_HOST=alcance_mais_pg
|
SQL_HOST=alcance_mais_pg
|
||||||
SQL_PORT=5432
|
SQL_PORT=5432
|
||||||
|
|
||||||
BREVO_API_KEY=
|
|
||||||
|
|
||||||
MINIO_ACCESS_KEY=
|
|
||||||
MINIO_ENDPOINT=
|
|
||||||
MINIO_SECRET_KEY=
|
|
||||||
MINIO_CONTAS_AVATARS_BUCKET=
|
|
||||||
MINIO_ENTREGAVEIS_BUCKET=
|
|
||||||
MINIO_CLIENTES_LOGOS_BUCKET=
|
|
||||||
|
|
||||||
# Recaptcha
|
# Recaptcha
|
||||||
RECAPTCHA_PRIVATE_KEY=
|
RECAPTCHA_PRIVATE_KEY=
|
||||||
RECAPTCHA_PUBLIC_KEY=
|
RECAPTCHA_PUBLIC_KEY=
|
||||||
RECAPTCHA_REQUIRED_SCORE=0.6
|
RECAPTCHA_REQUIRED_SCORE=0.6
|
||||||
|
|
||||||
# Celery
|
|
||||||
CELERY_BROKER_URL=redis://${REDIS_NAME}
|
|
||||||
CELERY_FLOWER_USER=
|
|
||||||
CELERY_FLOWER_PASSWORD=
|
|
||||||
|
|
||||||
# Gunicorn
|
# Gunicorn
|
||||||
WEB_CONCURRENCY=4
|
WEB_CONCURRENCY=4
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
from .celery import app as celery_app
|
|
||||||
|
|
||||||
__all__ = ("celery_app",)
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import os
|
|
||||||
from celery import Celery
|
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WYGIWYH.settings")
|
|
||||||
app = Celery("WYGIWYH")
|
|
||||||
app.config_from_object("django.conf:settings", namespace="CELERY")
|
|
||||||
app.autodiscover_tasks()
|
|
||||||
@@ -56,7 +56,7 @@ INSTALLED_APPS = [
|
|||||||
"django_tables2",
|
"django_tables2",
|
||||||
"django_filters",
|
"django_filters",
|
||||||
"apps.users.apps.UsersConfig",
|
"apps.users.apps.UsersConfig",
|
||||||
"django_celery_beat",
|
"procrastinate.contrib.django",
|
||||||
"apps.transactions.apps.TransactionsConfig",
|
"apps.transactions.apps.TransactionsConfig",
|
||||||
"apps.currencies.apps.CurrenciesConfig",
|
"apps.currencies.apps.CurrenciesConfig",
|
||||||
"apps.accounts.apps.AccountsConfig",
|
"apps.accounts.apps.AccountsConfig",
|
||||||
@@ -199,13 +199,6 @@ LOGIN_URL = "/login/"
|
|||||||
CRISPY_ALLOWED_TEMPLATE_PACKS = ["bootstrap5", "crispy_forms/pure_text"]
|
CRISPY_ALLOWED_TEMPLATE_PACKS = ["bootstrap5", "crispy_forms/pure_text"]
|
||||||
CRISPY_TEMPLATE_PACK = "bootstrap5"
|
CRISPY_TEMPLATE_PACK = "bootstrap5"
|
||||||
|
|
||||||
# Celery settings
|
|
||||||
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://redis")
|
|
||||||
CELERY_RESULT_BACKEND = os.getenv("CELERY_BROKER_URL", "redis://redis")
|
|
||||||
REDIS_URL = os.getenv("CELERY_BROKER_URL", "redis://redis")
|
|
||||||
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
|
|
||||||
|
|
||||||
|
|
||||||
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
|
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
|
||||||
SESSION_COOKIE_AGE = int(os.getenv("SESSION_EXPIRY_TIME", 2678400)) # 31 days
|
SESSION_COOKIE_AGE = int(os.getenv("SESSION_EXPIRY_TIME", 2678400)) # 31 days
|
||||||
SESSION_COOKIE_SECURE = os.getenv("HTTPS_ENABLED", "false").lower() == "true"
|
SESSION_COOKIE_SECURE = os.getenv("HTTPS_ENABLED", "false").lower() == "true"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from apps.transactions.models import Transaction
|
|||||||
@only_htmx
|
@only_htmx
|
||||||
@login_required
|
@login_required
|
||||||
@require_http_methods(["GET", "POST"])
|
@require_http_methods(["GET", "POST"])
|
||||||
def transaction_add(request, **kwargs):
|
def transaction_add(request):
|
||||||
month = int(request.GET.get("month", timezone.localdate(timezone.now()).month))
|
month = int(request.GET.get("month", timezone.localdate(timezone.now()).month))
|
||||||
year = int(request.GET.get("year", timezone.localdate(timezone.now()).year))
|
year = int(request.GET.get("year", timezone.localdate(timezone.now()).year))
|
||||||
transaction_type = Transaction.Type(request.GET.get("type", "IN"))
|
transaction_type = Transaction.Type(request.GET.get("type", "IN"))
|
||||||
|
|||||||
@@ -56,38 +56,12 @@ services:
|
|||||||
- '${SQL_PORT}:5432'
|
- '${SQL_PORT}:5432'
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
redis:
|
procrastinate:
|
||||||
image: docker.io/redis:6
|
|
||||||
restart: unless-stopped
|
|
||||||
container_name: wygiwyh_dev_redis
|
|
||||||
|
|
||||||
celeryworker:
|
|
||||||
<<: *django
|
<<: *django
|
||||||
image: wygiwyh_dev_celeryworker
|
image: wygiwyh_dev_procrastinate
|
||||||
container_name: wygiwyh_dev_celeryworker
|
container_name: wygiwyh_dev_procrastinate
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
|
||||||
- db
|
- db
|
||||||
ports: [ ]
|
ports: [ ]
|
||||||
command: /start-celeryworker
|
command: /start-procrastinate
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
celerybeat:
|
|
||||||
<<: *django
|
|
||||||
image: wygiwyh_dev_celerybeat
|
|
||||||
container_name: wygiwyh_dev_celerybeat
|
|
||||||
depends_on:
|
|
||||||
- redis
|
|
||||||
- db
|
|
||||||
ports: [ ]
|
|
||||||
command: /start-celerybeat
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
flower:
|
|
||||||
<<: *django
|
|
||||||
image: wygiwyh_dev_flower
|
|
||||||
container_name: wygiwyh_dev_flower
|
|
||||||
ports:
|
|
||||||
- '${FLOWER_OUTBOUND_PORT}:5555'
|
|
||||||
command: /start-flower
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -37,59 +37,15 @@ services:
|
|||||||
- POSTGRES_PASSWORD=${SQL_PASSWORD}
|
- POSTGRES_PASSWORD=${SQL_PASSWORD}
|
||||||
- POSTGRES_DB=${SQL_DATABASE}
|
- POSTGRES_DB=${SQL_DATABASE}
|
||||||
|
|
||||||
redis:
|
procrastinate:
|
||||||
image: docker.io/redis:6
|
|
||||||
container_name: ${REDIS_NAME}
|
|
||||||
restart: unless-stopped
|
|
||||||
command: redis-server --save 60 1 --loglevel warning
|
|
||||||
volumes:
|
|
||||||
- ./redis_data:/data
|
|
||||||
healthcheck:
|
|
||||||
test: [ "CMD", "redis-cli", "ping" ]
|
|
||||||
interval: 60s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 3
|
|
||||||
|
|
||||||
celeryworker:
|
|
||||||
<<: *django
|
<<: *django
|
||||||
image: ${CELERYWORKER_NAME}
|
image: ${PROCRASTINATE_NAME}
|
||||||
container_name: ${CELERYWORKER_NAME}
|
container_name: ${PROCRASTINATE_NAME}
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
|
||||||
- db
|
- db
|
||||||
ports: [ ]
|
ports: [ ]
|
||||||
command: /start-celeryworker
|
command: /start-procrastinate
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
|
||||||
test: [ "NONE" ]
|
|
||||||
|
|
||||||
celerybeat:
|
|
||||||
<<: *django
|
|
||||||
image: ${CELERYBEAT_NAME}
|
|
||||||
container_name: ${CELERYBEAT_NAME}
|
|
||||||
depends_on:
|
|
||||||
- redis
|
|
||||||
- db
|
|
||||||
ports: [ ]
|
|
||||||
command: /start-celerybeat
|
|
||||||
restart: unless-stopped
|
|
||||||
healthcheck:
|
|
||||||
test: [ "NONE" ]
|
|
||||||
|
|
||||||
flower:
|
|
||||||
<<: *django
|
|
||||||
image: ${FLOWER_NAME}
|
|
||||||
container_name: ${FLOWER_NAME}
|
|
||||||
ports:
|
|
||||||
- '5556:5555'
|
|
||||||
command: /start-flower
|
|
||||||
restart: unless-stopped
|
|
||||||
healthcheck:
|
|
||||||
test: curl --fail http://localhost:5555/healthcheck || exit 1
|
|
||||||
interval: 60s
|
|
||||||
timeout: 30s
|
|
||||||
retries: 3
|
|
||||||
start_period: 360s
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
|
|
||||||
rm -f './celerybeat.pid'
|
|
||||||
exec watchfiles --filter python celery.__main__.main --args '-A WYGIWYH.celery_app beat -l INFO'
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
exec watchfiles --filter python celery.__main__.main \
|
|
||||||
--args \
|
|
||||||
"-A WYGIWYH.celery_app -b \"${CELERY_BROKER_URL}\" flower
|
|
||||||
--basic_auth=\"${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}\""
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
|
|
||||||
exec watchfiles --filter python celery.__main__.main --args '-A WYGIWYH.celery_app worker -l INFO'
|
|
||||||
@@ -39,17 +39,9 @@ COPY ./docker/dev/django/start /start
|
|||||||
RUN sed -i 's/\r$//g' /start
|
RUN sed -i 's/\r$//g' /start
|
||||||
RUN chmod +x /start
|
RUN chmod +x /start
|
||||||
|
|
||||||
COPY ./docker/dev/celery/worker/start /start-celeryworker
|
COPY ./docker/dev/procrastinate/start /start-procrastinate
|
||||||
RUN sed -i 's/\r$//g' /start-celeryworker
|
RUN sed -i 's/\r$//g' /start-procrastinate
|
||||||
RUN chmod +x /start-celeryworker
|
RUN chmod +x /start-procrastinate
|
||||||
|
|
||||||
COPY ./docker/dev/celery/beat/start /start-celerybeat
|
|
||||||
RUN sed -i 's/\r$//g' /start-celerybeat
|
|
||||||
RUN chmod +x /start-celerybeat
|
|
||||||
|
|
||||||
COPY ./docker/dev/celery/flower/start /start-flower
|
|
||||||
RUN sed -i 's/\r$//g' /start-flower
|
|
||||||
RUN chmod +x /start-flower
|
|
||||||
|
|
||||||
# copy project
|
# copy project
|
||||||
COPY ./app .
|
COPY ./app .
|
||||||
|
|||||||
7
docker/dev/procrastinate/start
Normal file
7
docker/dev/procrastinate/start
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
|
||||||
|
exec watchfiles --filter python "python manage.py procrastinate worker"
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
|
|
||||||
rm -f './celerybeat.pid'
|
|
||||||
exec watchfiles --filter python celery.__main__.main --args '-A WYGIWYH.celery_app beat -l INFO'
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
exec watchfiles --filter python celery.__main__.main \
|
|
||||||
--args \
|
|
||||||
"-A WYGIWYH.celery_app -b \"${CELERY_BROKER_URL}\" flower
|
|
||||||
--basic_auth=\"${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}\""
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
|
|
||||||
exec watchfiles --filter python celery.__main__.main --args '-A WYGIWYH.celery_app worker -l INFO'
|
|
||||||
@@ -51,17 +51,9 @@ COPY --chown=app:app ./docker/prod/django/start /start
|
|||||||
RUN sed -i 's/\r$//g' /start
|
RUN sed -i 's/\r$//g' /start
|
||||||
RUN chmod +x /start
|
RUN chmod +x /start
|
||||||
|
|
||||||
COPY --chown=app:app ./docker/prod/celery/worker/start /start-celeryworker
|
COPY --chown=app:app ./docker/prod/procrastinate/start /start-procrastinate
|
||||||
RUN sed -i 's/\r$//g' /start-celeryworker
|
RUN sed -i 's/\r$//g' /start-procrastinate
|
||||||
RUN chmod +x /start-celeryworker
|
RUN chmod +x /start-procrastinate
|
||||||
|
|
||||||
COPY --chown=app:app ./docker/prod/celery/beat/start /start-celerybeat
|
|
||||||
RUN sed -i 's/\r$//g' /start-celerybeat
|
|
||||||
RUN chmod +x /start-celerybeat
|
|
||||||
|
|
||||||
COPY --chown=app:app ./docker/prod/celery/flower/start /start-flower
|
|
||||||
RUN sed -i 's/\r$//g' /start-flower
|
|
||||||
RUN chmod +x /start-flower
|
|
||||||
|
|
||||||
# copy project
|
# copy project
|
||||||
COPY ./app .
|
COPY ./app .
|
||||||
|
|||||||
7
docker/prod/procrastinate/start
Normal file
7
docker/prod/procrastinate/start
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
|
||||||
|
exec python manage.py procrastinate worker
|
||||||
@@ -18,12 +18,7 @@ drf-spectacular~=0.27.2
|
|||||||
gunicorn==21.2.0
|
gunicorn==21.2.0
|
||||||
whitenoise[brotli]==6.6.0
|
whitenoise[brotli]==6.6.0
|
||||||
|
|
||||||
# Celery
|
|
||||||
redis==5.0.1 # https://github.com/redis/redis-py
|
|
||||||
hiredis==2.3.2 # https://github.com/redis/hiredis-py
|
|
||||||
celery==5.3.6 # pyup: < 6.0 # https://github.com/celery/celery
|
|
||||||
django-celery-beat~=2.7.0 # https://github.com/celery/django-celery-beat
|
|
||||||
flower==2.0.1 # https://github.com/mher/flower
|
|
||||||
watchfiles==0.24.0 # https://github.com/samuelcolvin/watchfiles
|
watchfiles==0.24.0 # https://github.com/samuelcolvin/watchfiles
|
||||||
|
procrastinate[django]~=2.14
|
||||||
|
|
||||||
requests~=2.32.3
|
requests~=2.32.3
|
||||||
|
|||||||
Reference in New Issue
Block a user