From 6455cf7852129b9dfcc0a7679df254a4e44533c6 Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Wed, 4 Jul 2018 17:45:51 +0800 Subject: Enable celery for vesagent workers for ocata Change-Id: Ibf07426ec3fa8b9c8b866d95a1e49537094cef70 Issue-ID: MULTICLOUD-230 Signed-off-by: Yun Huang --- ocata/docker/Dockerfile | 2 +- ocata/ocata/__init__.py | 7 +++++++ ocata/ocata/celery.py | 38 ++++++++++++++++++++++++++++++++++++++ ocata/requirements.txt | 4 ++++ ocata/run.sh | 5 +++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ocata/ocata/celery.py (limited to 'ocata') diff --git a/ocata/docker/Dockerfile b/ocata/docker/Dockerfile index cca1cf89..97bbc7ba 100644 --- a/ocata/docker/Dockerfile +++ b/ocata/docker/Dockerfile @@ -18,7 +18,7 @@ ENV AAI_PASSWORD "AAI" EXPOSE 9006 WORKDIR /opt/ocata -RUN apt-get update && apt-get install -y memcached unzip +RUN apt-get update && apt-get install -y memcached unzip rabbitmq-server RUN wget -O /opt/multicloud-openstack-ocata.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.multicloud.openstack&a=multicloud-openstack-ocata&e=zip&v=LATEST" && \ unzip -q -o -B /opt/multicloud-openstack-ocata.zip -d /opt/ && \ rm -f /opt/multicloud-openstack-ocata.zip diff --git a/ocata/ocata/__init__.py b/ocata/ocata/__init__.py index afa702d3..f7fd66a2 100644 --- a/ocata/ocata/__init__.py +++ b/ocata/ocata/__init__.py @@ -12,3 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, unicode_literals + +# This will make sure the app is always imported when +# Django starts so that shared_task will use this app. +from .celery import app as celery_app + +__all__ = ['celery_app'] diff --git a/ocata/ocata/celery.py b/ocata/ocata/celery.py new file mode 100644 index 00000000..ee533b5d --- /dev/null +++ b/ocata/ocata/celery.py @@ -0,0 +1,38 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, unicode_literals +import os +from celery import Celery +import logging + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ocata.settings') + +app = Celery('ocata') + +# Using a string here means the worker doesn't have to serialize +# the configuration object to child processes. +# - namespace='CELERY' means all celery-related configuration keys +# should have a `CELERY_` prefix. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks() + +logger = logging.getLogger(__name__) + +@app.task(bind=True) +def debug_task(self): + logger.debug("self.request") diff --git a/ocata/requirements.txt b/ocata/requirements.txt index 5408c53b..260e1bad 100644 --- a/ocata/requirements.txt +++ b/ocata/requirements.txt @@ -21,3 +21,7 @@ unittest_xml_reporting==1.12.0 # for onap logging onappylog>=1.0.6 + +# for background tasks +celery >= 4.0 + diff --git a/ocata/run.sh b/ocata/run.sh index 70af4df9..541eaf10 100755 --- a/ocata/run.sh +++ b/ocata/run.sh @@ -15,4 +15,9 @@ memcached -d -m 2048 -u root -c 1024 -p 11211 -P /tmp/memcached1.pid export PYTHONPATH=lib/share + +service rabbitmq-server restart +# make sure only 1 worker due to missing the synchronization between workers now +nohup celery -A ocata worker --concurrency=1 --loglevel=debug & + uwsgi --http :9006 --module ocata.wsgi --master --processes 4 -- cgit 1.2.3-korg