Fixed celery tasks

pull/78/head
Konstantin Gründger 2019-09-21 16:49:27 +02:00 zatwierdzone przez Meisterschueler
rodzic 2c29cc9b7a
commit 08a26eb99a
9 zmienionych plików z 22 dodań i 25 usunięć

Wyświetl plik

@ -5,12 +5,11 @@ from flask_migrate import Migrate
from flask_caching import Cache
from celery import Celery
from app.flask_celery import make_celery
bootstrap = Bootstrap()
db = SQLAlchemy()
migrate = Migrate()
cache = Cache()
celery = Celery(__name__, broker='redis://localhost:6379/0')
def create_app(config_name='development'):
@ -23,6 +22,7 @@ def create_app(config_name='development'):
else:
app.config.from_object('app.config.default')
app.config.from_envvar("OGN_CONFIG_MODULE", silent=True)
celery.config_from_object(app.config)
# Initialize other things
bootstrap.init_app(app)
@ -30,8 +30,6 @@ def create_app(config_name='development'):
migrate.init_app(app, db)
cache.init_app(app)
# celery = make_celery(app)
from app.main import bp as bp_main
app.register_blueprint(bp_main)

Wyświetl plik

@ -1,14 +0,0 @@
from celery import Celery
def make_celery(app):
celery = Celery(app.import_name, backend=app.config["CELERY_RESULT_BACKEND"], broker=app.config["CELERY_BROKER_URL"])
celery.conf.update(app.config)
class ContextTask(celery.Task):
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery

Wyświetl plik

@ -1,7 +1,8 @@
import enum
class DeviceInfoOrigin(enum.Enum):
UNKNOWN = 0
OGN_DDB = 1
FLARMNET = 2
USER_DEFINED = 3
USER_DEFINED = 3

7
celery_worker.py 100644
Wyświetl plik

@ -0,0 +1,7 @@
#!/usr/bin/env python
import os
from app import celery, create_app
from app.collect.celery import *
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app.app_context().push()

Wyświetl plik

@ -1,6 +1,7 @@
[program:celerybeat]
command=/home/pi/ogn-python/venv/bin/celery -A app.collect beat -l info
command=/home/pi/ogn-python/venv/bin/celery -A celery_worker.celery beat -l info
directory=/home/pi/ogn-python
environment=FLASK_APP=ogn_python.py
user=pi
numprocs=1
@ -11,4 +12,4 @@ autorestart=true
startsecs=10
; Causes supervisor to send the termination signal (SIGTERM) to the whole process group.
stopasgroup=true
stopasgroup=true

Wyświetl plik

@ -1,6 +1,7 @@
[program:celery]
command=/home/pi/ogn-python/venv/bin/celery -A app.collect worker -l info
command=/home/pi/ogn-python/venv/bin/celery -A celery_worker.celery worker -l info
directory=/home/pi/ogn-python
environment=FLASK_APP=ogn_python.py
user=pi
numprocs=1
@ -15,4 +16,4 @@ startsecs=10
stopwaitsecs = 600
; Causes supervisor to send the termination signal (SIGTERM) to the whole process group.
stopasgroup=true
stopasgroup=true

Wyświetl plik

@ -1,4 +1,5 @@
[program:flower]
environment=OGN_CONFIG_MODULE='config/default.py'
command=/home/pi/ogn-python/venv/bin/celery flower -A app.celery --port=5555 -l info
directory=/home/pi/ogn-python

Wyświetl plik

@ -1,4 +1,5 @@
[program:gunicorn]
environment=OGN_CONFIG_MODULE='config/default.py'
command=/home/pi/ogn-python/venv/bin/gunicorn --bind :5000 ogn_python:app
directory=/home/pi/ogn-python

Wyświetl plik

@ -1,9 +1,10 @@
[program:ogn-feeder]
command=/home/pi/ogn-python/venv/bin/python -m flask gateway run
command=/home/pi/ogn-python/venv/bin/flask gateway run
directory=/home/pi/ogn-python
environment=FLASK_APP=ogn_python.py
user=pi
stderr_logfile=/var/log/supervisor/ogn-feeder.log
stdout_logfile=/var/log/supervisor/ogn-feeder.log
autostart=true
autorestart=true
autorestart=true