Skip to content

Commit

Permalink
Upgrade to celery 5
Browse files Browse the repository at this point in the history
  • Loading branch information
pchlap committed Feb 1, 2022
1 parent 945b67b commit b9eb450
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 56 deletions.
5 changes: 5 additions & 0 deletions celery_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export REDIS_HOST=redis
export REDIS_PORT=6379

celery --app=service:celery beat --loglevel=INFO &
celery --app=service:celery worker --loglevel=INFO &
7 changes: 4 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
redis-server --daemonize yes

# Run celery beat and worker
celery beat --app=service:celery --loglevel=INFO &
celery worker --app=service:celery --loglevel=INFO &
celery --app=service:celery beat --loglevel=INFO &
celery --app=service:celery worker --loglevel=INFO &

# Run the gunicorn server
exec gunicorn -b :8000 --timeout 300 --graceful-timeout 60 --access-logfile - --error-logfile - service:app
#exec gunicorn -b :8000 --certfile=service.crt --keyfile=service.key --timeout 300 --graceful-timeout 60 --access-logfile - --error-logfile - service:app
exec gunicorn -b :8000 --timeout 300 --graceful-timeout 60 --access-logfile - --error-logfile - service:app
52 changes: 0 additions & 52 deletions platipy/backend/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@

import json
import os
import tempfile

from flask import Flask
from celery import current_app
from celery.bin import worker
from celery.bin import beat
from multiprocessing import Process
from loguru import logger
import pydicom

Expand Down Expand Up @@ -57,42 +52,6 @@ def decorator(f):

return decorator

def run_celery(self):

if self.celery_started:
return

application = current_app._get_current_object()

celery_worker = worker.worker(app=application)

options = {
"broker": self.config["CELERY_BROKER_URL"],
"loglevel": "INFO",
"traceback": True,
}

celery_worker.run(**options)

def run_beat(self):

if self.beat_started:
return

application = current_app._get_current_object()

celery_beat = beat.beat(app=application)

options = {
"broker": self.config["CELERY_BROKER_URL"],
"loglevel": "INFO",
"traceback": True,
"beat": True,
"schedule": os.path.join(str(tempfile.mkdtemp()), "celery-beat-schedule"),
}

celery_beat.run(**options)

def run(
self,
host=None,
Expand All @@ -106,14 +65,6 @@ def run(

logger.info("Starting APP!")

process_celery = Process(target=self.run_celery)
process_celery.start()
self.celery_started = True

process_beat = Process(target=self.run_beat)
process_beat.start()
self.beat_started = True

self.dicom_listener_port = dicom_listener_port
self.dicom_listener_aetitle = dicom_listener_aetitle

Expand All @@ -128,9 +79,6 @@ def run(
**options
)

process_celery.join()
process_beat.join()

def run_dicom_listener(self, listen_port, listen_ae_title):
"""
Background task that listens at a specific port for incoming dicom series
Expand Down
2 changes: 1 addition & 1 deletion requirements-backend.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
flask >= 1.1.2
flask-restful >= 0.3.8
flask-sqlalchemy >= 2.4.4
celery >= 4.4.7,< 5.0.0
celery >= 5.2.3
redis >= 3.5.3
psutil >= 5.8.0
gunicorn >= 20.0.4

0 comments on commit b9eb450

Please sign in to comment.