Move code from gvaweb to webtasks

This change allows celery to find its tasks under the expected webtasks
namespace.
This commit is contained in:
Jan Dittberner 2020-03-03 15:22:51 +01:00
parent 9e48e068e2
commit 3b05272254
7 changed files with 38 additions and 35 deletions

View file

@ -4,4 +4,4 @@ set -e
. /home/gvaweb/gvaweb-venv/bin/activate
cd /srv/gvaweb/gvaweb
celery -A gvaweb worker -Q web -l info
celery -A webtasks worker -Q web -l info

View file

@ -1,4 +0,0 @@
"""
This module contains :py:mod:`webtasks.tasks`.
"""

View file

@ -0,0 +1,10 @@
"""
This module contains :py:mod:`webtasks.tasks`.
"""
__version__ = "0.2.0"
from webtasks.celery import app as celery_app
__all__ = ("celery_app",)

View file

@ -7,7 +7,7 @@ This module defines the Celery_ app for gvaweb.
from celery import Celery
#: The Celery application
app = Celery('gvaweb')
app = Celery("webtasks")
app.config_from_object('gvaweb.settings')
app.autodiscover_tasks(['gvaweb.webtasks'], force=True)
app.config_from_object("webtasks.settings", namespace="CELERY")
app.autodiscover_tasks(["webtasks.tasks"], force=True)

View file

@ -25,22 +25,20 @@ def get_env_setting(setting):
########## CELERY CONFIGURATION
CELERY_TIMEZONE = 'Europe/Berlin'
CELERY_TIMEZONE = "Europe/Berlin"
CELERY_ENABLE_UTC = True
CELERY_RESULT_BACKEND = 'amqp'
CELERY_RESULT_PERSISTENT = True
CELERY_TASK_RESULT_EXPIRES = None
CELERY_ROUTES = (
'gvacommon.celeryrouters.GvaRouter',
)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
BROKER_URL = get_env_setting('GVAWEB_BROKER_URL')
CELERY_ROUTES = ("gvacommon.celeryrouters.GvaRouter",)
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_RESULT_BACKEND = get_env_setting("GVAWEB_RESULTS_REDIS_URL")
CELERY_BROKER_URL = get_env_setting("GVAWEB_BROKER_URL")
########## END CELERY CONFIGURATION
########## GVAWEB CONFIGURATION
GVAWEB_NGINX_SITES_AVAILABLE = get_env_setting('GVAWEB_NGINX_SITES_AVAILABLE')
GVAWEB_NGINX_SITES_ENABLED = get_env_setting('GVAWEB_NGINX_SITES_ENABLED')
GVAWEB_WWWUSER_MOUNT = get_env_setting('GVAWEB_WWWUSER_MOUNT')
GVAWEB_NGINX_SITES_AVAILABLE = get_env_setting("GVAWEB_NGINX_SITES_AVAILABLE")
GVAWEB_NGINX_SITES_ENABLED = get_env_setting("GVAWEB_NGINX_SITES_ENABLED")
GVAWEB_WWWUSER_MOUNT = get_env_setting("GVAWEB_WWWUSER_MOUNT")
########## END GVAWEB CONFIGURATION

View file

@ -10,9 +10,7 @@ from jinja2 import Environment, PackageLoader
from celery import shared_task
from celery.utils.log import get_task_logger
from gvaweb import settings
from webtasks import settings
_LOGGER = get_task_logger(__name__)
@ -22,14 +20,14 @@ LN_CMD = '/bin/ln'
SERVICE_CMD = '/bin/systemctl'
INSTALL_CMD = '/usr/bin/install'
JINJAENV = Environment(loader=PackageLoader('gvaweb.webtasks', 'templates'))
JINJA_ENV = Environment(loader=PackageLoader('webtasks', 'templates'))
def _jinja_parentdomain(domain):
return '.'.join(domain.split('.')[1:])
JINJAENV.filters['parentdomain'] = _jinja_parentdomain
JINJA_ENV.filters['parentdomain'] = _jinja_parentdomain
def log_and_raise(exception, message, *args):
@ -57,7 +55,7 @@ def _build_document_root_path(sitename, username):
def _get_template(templatename):
return JINJAENV.get_template(templatename)
return JINJA_ENV.get_template(templatename)
@shared_task
@ -74,16 +72,16 @@ def create_web_vhost_config(username, sitename, wildcard):
:rtype: boolean
"""
conftmpl = _get_template('vhost.nginx')
confdata = conftmpl.render(domain=sitename, wildcard=wildcard)
conffile = None
config_template = _get_template('vhost.nginx')
config_data = config_template.render(domain=sitename, wildcard=wildcard)
config_file = None
try:
nginxtemp, filename = mkstemp()
conffile = os.fdopen(nginxtemp, 'w')
conffile.write(confdata.encode('utf8'))
nginx_temp_file, filename = mkstemp()
config_file = os.fdopen(nginx_temp_file, 'w')
config_file.write(config_data.encode('utf8'))
finally:
if conffile:
conffile.close()
if config_file:
config_file.close()
try:
subprocess.check_output([
SUDO_CMD, INSTALL_CMD, '-o', 'root', '-g', 'root', '-m', '0640',
@ -176,7 +174,7 @@ def create_web_php_fpm_pool_config(username):
:rtype: boolean
"""
# TODO: implement PHP FPM docker management
# TODO: implement PHP FPM docker management setup
return True
@ -190,4 +188,5 @@ def delete_web_php_fpm_pool_config(username):
:rtype: boolean
"""
# TODO: implement PHP FPM docker management removal
return True