Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump python version to 3.10 and libraries to more recent versions #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ To change the endpoints, update the code in [api/app.py](api/app.py)

Task changes should happen in [celery-queue/tasks.py](celery-queue/tasks.py)


### Setup considerations

From: [Redis administration](https://redis.io/docs/management/admin/)

```
Make sure to set Linux kernel overcommit memory setting to 1.

This can be done by adding vm.overcommit_memory=1 to /etc/sysctl.conf. Then, reboot or run the command sysctl vm.overcommit_memory=1 to activate the setting.
```

---

adapted from [https://github.com/itsrifat/flask-celery-docker-scale](https://github.com/itsrifat/flask-celery-docker-scale)
3 changes: 1 addition & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM python:3.9-alpine
FROM python:3.10-alpine

ENV CELERY_BROKER_URL redis://redis:6379/0
ENV CELERY_RESULT_BACKEND redis://redis:6379/0
ENV C_FORCE_ROOT true

ENV HOST 0.0.0.0
ENV PORT 5001
Expand Down
3 changes: 1 addition & 2 deletions api/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM python:3.9-alpine
FROM python:3.10-alpine

ENV CELERY_BROKER_URL redis://redis:6379/0
ENV CELERY_RESULT_BACKEND redis://redis:6379/0
ENV C_FORCE_ROOT true

ENV HOST 0.0.0.0
ENV PORT 5001
Expand Down
6 changes: 3 additions & 3 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==2.0.1
celery==5.1.2
redis==3.5.3
Flask==2.3.2
celery==5.3.1
redis==4.6.0
9 changes: 7 additions & 2 deletions api/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379'),
CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'redis://localhost:6379')


celery = Celery('tasks', broker=CELERY_BROKER_URL, backend=CELERY_RESULT_BACKEND)
celery = Celery(__name__,
broker=CELERY_BROKER_URL,
backend=CELERY_RESULT_BACKEND,
broker_connection_retry=True,
broker_connection_retry_on_startup=True,
broker_connection_max_retries=10,
)
3 changes: 1 addition & 2 deletions celery-queue/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM python:3.9-alpine
FROM python:3.10-alpine

ENV CELERY_BROKER_URL redis://redis:6379/0
ENV CELERY_RESULT_BACKEND redis://redis:6379/0
ENV C_FORCE_ROOT true

COPY . /queue
WORKDIR /queue
Expand Down
5 changes: 2 additions & 3 deletions celery-queue/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM python:3.9-alpine
FROM python:3.10-alpine

ENV CELERY_BROKER_URL redis://redis:6379/0
ENV CELERY_RESULT_BACKEND redis://redis:6379/0
ENV C_FORCE_ROOT true

COPY . /queue
WORKDIR /queue
Expand All @@ -11,4 +10,4 @@ RUN pip install -U setuptools pip
RUN pip install -r requirements.txt

# hot code reloading
CMD watchmedo auto-restart --directory=./ --pattern=*.py --recursive -- celery -A tasks worker --concurrency=1 --loglevel=INFO -E
CMD watchmedo auto-restart --directory=./ --pattern=*.py --recursive -- celery -A tasks worker --concurrency=1 --loglevel=INFO --uid=nobody --gid=nogroup -E
9 changes: 4 additions & 5 deletions celery-queue/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
celery==5.1.2
flower==1.0.0
redis==3.5.3
watchdog==2.1.5

celery==5.3.1
flower==2.0.0
redis==4.6.0
watchdog==3.0.0
8 changes: 7 additions & 1 deletion celery-queue/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379'),
CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'redis://localhost:6379')

celery = Celery('tasks', broker=CELERY_BROKER_URL, backend=CELERY_RESULT_BACKEND)
celery = Celery(__name__,
broker=CELERY_BROKER_URL,
backend=CELERY_RESULT_BACKEND,
broker_connection_retry=True,
broker_connection_retry_on_startup=True,
broker_connection_max_retries=10,
)


@celery.task(name='tasks.add')
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
build:
context: ./celery-queue
dockerfile: Dockerfile.dev
command: celery -A tasks worker -l info -E
command: celery -A tasks worker -l info --uid=nobody --gid=nogroup -E
environment:
CELERY_BROKER_URL: redis://redis
CELERY_RESULT_BACKEND: redis://redis
Expand All @@ -30,7 +30,7 @@ services:
dockerfile: Dockerfile.dev
ports:
- "5555:5555"
command: ['celery', 'flower', '-A', 'tasks']
command: ['celery', '-A', 'tasks', 'flower']
environment:
CELERY_BROKER_URL: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/0
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
build:
context: ./celery-queue
dockerfile: Dockerfile
command: celery -A tasks worker -l info -E
command: celery -A tasks worker -l info --uid=nobody --gid=nogroup -E
environment:
CELERY_BROKER_URL: redis://redis
CELERY_RESULT_BACKEND: redis://redis
Expand All @@ -27,7 +27,7 @@ services:
dockerfile: Dockerfile
ports:
- "5555:5555"
command: ['celery', 'flower', '-A', 'tasks']
command: ['celery', '-A', 'tasks', 'flower']
environment:
CELERY_BROKER_URL: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/0
Expand Down