Add celery app instance with base config

This patch allows to schedule tasks and launch workers with basic
config. To launch a worker:

    celery -A module_build_service.celery_app -l info

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2019-11-13 17:17:42 +08:00
parent 56b0012b4f
commit ddfb5b780c
5 changed files with 29 additions and 0 deletions

View File

@@ -92,6 +92,18 @@ class BaseConfiguration(object):
# Disable Client Authorization
NO_AUTH = False
# Configs for running tasks asynchronously with Celery
# For details of Celery configs, refer to Celery documentation:
# https://docs.celeryproject.org/en/latest/userguide/configuration.html
#
# Each config name consists of namespace CELERY_ and the new Celery config
# name converted to upper case. For example the broker url, Celery config
# name is broker_url, then as you can below, the corresponding config name
# in MBS is CELERY_BROKER_URL.
CELERY_BROKER_URL = ""
CELERY_RESULT_BACKEND = ""
CELERY_IMPORTS = []
class TestConfiguration(BaseConfiguration):
BUILD_LOGS_DIR = "/tmp"
@@ -155,3 +167,6 @@ class OfflineLocalBuildConfiguration(LocalBuildConfiguration):
class DevConfiguration(LocalBuildConfiguration):
DEBUG = True
LOG_BACKEND = "console"
CELERY_BROKER_URL = "redis://localhost:6379/0"
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"

View File

@@ -42,6 +42,7 @@ RUN yum -y install \
python-solv \
python-sqlalchemy \
python-tox \
python2-celery \
python2-libmodulemd2 \
python2-pyyaml \
python2-pungi \

View File

@@ -9,6 +9,7 @@ RUN dnf -y install \
git-core \
createrepo_c \
rsync \
python3-celery \
python3-fedmsg \
python3-kobo-rpmlib \
python3-rpm \

View File

@@ -19,10 +19,12 @@ for a number of tasks:
"""
import pkg_resources
from celery import Celery
from flask import Flask, has_app_context, url_for
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.pool import StaticPool
from logging import getLogger
import gi # noqa
gi.require_version("Modulemd", "2.0") # noqa
from gi.repository import Modulemd # noqa
@@ -46,6 +48,15 @@ app.wsgi_app = ReverseProxy(app.wsgi_app)
conf = init_config(app)
celery_app = Celery("module-build-service")
# Convert config names specific for Celery like this:
# celery_broker_url -> broker_url
celery_configs = {
name[7:]: getattr(conf, name)
for name in dir(conf) if name.startswith('celery_')
}
celery_app.conf.update(**celery_configs)
class MBSSQLAlchemy(SQLAlchemy):
"""

View File

@@ -18,3 +18,4 @@ pygobject
requests
six
sqlalchemy
celery