Refactor module structure

Move pgsqltasks to top level to keep the task names when using Python 3
This commit is contained in:
Jan Dittberner 2020-03-04 18:14:08 +01:00
parent acf2b171a9
commit 68f0834954
12 changed files with 67 additions and 84 deletions

View file

@ -1,6 +1,8 @@
Changelog Changelog
========= =========
* :support:`-` move pgsqltasks to top level to keep the task names when
using Python 3
* :support:`-` use Pipenv for dependency management * :support:`-` use Pipenv for dependency management
* :release:`0.2.0 <2018-11-21>` * :release:`0.2.0 <2018-11-21>`

View file

@ -7,30 +7,24 @@ gvapgsql is implemented as `Celery`_ app.
.. _Celery: http://www.celeryproject.org/ .. _Celery: http://www.celeryproject.org/
The project module :py:mod:`gvapgsql`
=====================================
.. automodule:: gvapgsql
:py:mod:`gvapgsql.celery`
-------------------------
.. automodule:: gvapgsql.celery
:members:
:py:mod:`gvapgsql.settings`
---------------------------
.. automodule:: gvapgsql.settings
:py:mod:`pgsqltasks` app :py:mod:`pgsqltasks` app
======================== ========================
:py:mod:`pgsqltasks.celery`
---------------------------
.. automodule:: pgsqltasks .. automodule:: pgsqltasks
.. automodule:: pgsqltasks.celery
:members:
:py:mod:`pgsqltasks.settings`
-----------------------------
.. automodule:: pgsqltasks.settings
:py:mod:`pgsqltasks.tasks` :py:mod:`pgsqltasks.tasks`
-------------------------- --------------------------

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# pymode:lint_ignore=E501 # pymode:lint_ignore=E501
# #
# gvamysql documentation build configuration file, created by # gvapgsql documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 17 11:46:20 2013. # sphinx-quickstart on Sun Feb 17 11:46:20 2013.
# #
# This file is execfile()d with the current directory set to its containing dir. # This file is execfile()d with the current directory set to its containing dir.
@ -35,13 +35,13 @@ os.environ['GVAPGSQL_DBADMIN_PASSWORD'] = 'gvapgsql'
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['releases', 'sphinx.ext.autodoc', 'celery.contrib.sphinx'] extensions = ['releases', 'sphinx.ext.autodoc', 'celery.contrib.sphinx']
# configuration for releases extension
releases_issue_uri = 'https://git.dittberner.info/gnuviech/gvapgsql/issues/%s'
releases_release_uri = 'https://git.dittberner.info/gnuviech/gvapgsql/stc/tag/%s'
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
releases_issue_uri = 'https://dev.gnuviech-server.de/gvapgsql/ticket/%s'
releases_release_uri = 'https://dev.gnuviech-server.de/gvapgsql/milestone/%s'
# The suffix of source filenames. # The suffix of source filenames.
source_suffix = '.rst' source_suffix = '.rst'
@ -53,16 +53,17 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'gvapgsql' project = u'gvapgsql'
copyright = u'2015-2018 Jan Dittberner' copyright = u'2015-2020 Jan Dittberner'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# #
# The short X.Y version.
version = '0.2'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '0.2.0' from pgsqltasks import __version__ as release
# The short X.Y version.
version = ".".join(release.split('.')[:2])
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@ -103,7 +104,7 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
html_theme = 'default' html_theme = 'alabaster'
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the

View file

@ -1,3 +0,0 @@
.*.swp
*.pyc
.ropeproject/

View file

@ -3,13 +3,8 @@ from __future__ import unicode_literals
class GvaRouter(object): class GvaRouter(object):
def route_for_task(self, task, args=None, kwargs=None): def route_for_task(self, task, args=None, kwargs=None):
for route in ['ldap', 'file', 'mysql', 'pgsql']: for route in ["ldap", "file", "mysql", "pgsql"]:
if route in task: if route in task:
return { return {"exchange": route, "exchange_type": "direct", "queue": route}
'exchange': route,
'exchange_type': 'direct',
'queue': route,
}
return None return None

View file

@ -1,15 +0,0 @@
"""
This module defines the Celery_ app for gvapgsql.
.. _Celery: http://www.celeryproject.org/
"""
from __future__ import absolute_import
from celery import Celery
#: The Celery application
app = Celery('gvapgsql')
app.config_from_object('gvapgsql.settings')
app.autodiscover_tasks(['pgsqltasks'], force=True)

View file

@ -2,3 +2,9 @@
This module contains :py:mod:`pgsqltasks.tasks`. This module contains :py:mod:`pgsqltasks.tasks`.
""" """
__version__ = "0.3.0"
from pgsqltasks.celery import app as celery_app
__all__ = ("celery_app",)

View file

@ -0,0 +1,13 @@
"""
This module defines the Celery_ app for gvapgsql.
.. _Celery: http://www.celeryproject.org/
"""
from celery import Celery
#: The Celery application
app = Celery("pgsqltasks")
app.config_from_object("pgsqltasks.settings")
app.autodiscover_tasks(["pgsqltasks.tasks"], force=True)

View file

@ -1,4 +0,0 @@
"""
Empty models to make Django accept pgsqltasks as an app.
"""

View file

@ -25,23 +25,21 @@ def get_env_setting(setting):
########## CELERY CONFIGURATION ########## CELERY CONFIGURATION
CELERY_TIMEZONE = 'Europe/Berlin' CELERY_BROKER_URL = get_env_setting("GVAPGSQL_BROKER_URL")
CELERY_ENABLE_UTC = True CELERY_RESULT_BACKEND = get_env_setting("GVAPGSQL_RESULTS_REDIS_URL")
CELERY_RESULT_BACKEND = 'amqp'
CELERY_RESULT_PERSISTENT = True
CELERY_TASK_RESULT_EXPIRES = None CELERY_TASK_RESULT_EXPIRES = None
CELERY_ROUTES = ( CELERY_ROUTES = ("gvacommon.celeryrouters.GvaRouter",)
'gvacommon.celeryrouters.GvaRouter', CELERY_TIMEZONE = "Europe/Berlin"
) CELERY_ENABLE_UTC = True
CELERY_ACCEPT_CONTENT = ['json'] CELERY_RESULT_PERSISTENT = True
CELERY_TASK_SERIALIZER = 'json' CELERY_ACCEPT_CONTENT = ["json"]
CELERY_RESULT_SERIALIZER = 'json' CELERY_TASK_SERIALIZER = "json"
BROKER_URL = get_env_setting('GVAPGSQL_BROKER_URL') CELERY_RESULT_SERIALIZER = "json"
########## END CELERY CONFIGURATION ########## END CELERY CONFIGURATION
########## GVAPGSQL CONFIGURATION ########## GVAPGSQL CONFIGURATION
GVAPGSQL_DBADMIN_HOST = get_env_setting('GVAPGSQL_DBADMIN_HOST') GVAPGSQL_DBADMIN_HOST = get_env_setting("GVAPGSQL_DBADMIN_HOST")
GVAPGSQL_DBADMIN_PORT = int(get_env_setting('GVAPGSQL_DBADMIN_PORT')) GVAPGSQL_DBADMIN_PORT = int(get_env_setting("GVAPGSQL_DBADMIN_PORT"))
GVAPGSQL_DBADMIN_USER = get_env_setting('GVAPGSQL_DBADMIN_USER') GVAPGSQL_DBADMIN_USER = get_env_setting("GVAPGSQL_DBADMIN_USER")
GVAPGSQL_DBADMIN_PASSWORD = get_env_setting('GVAPGSQL_DBADMIN_PASSWORD') GVAPGSQL_DBADMIN_PASSWORD = get_env_setting("GVAPGSQL_DBADMIN_PASSWORD")
########## END GVAPGSQL CONFIGURATION ########## END GVAPGSQL CONFIGURATION

View file

@ -2,15 +2,12 @@
This module defines Celery_ tasks to manage PostgreSQL users and databases. This module defines Celery_ tasks to manage PostgreSQL users and databases.
""" """
from __future__ import absolute_import
from celery import shared_task from celery import shared_task
from celery.utils.log import get_task_logger from celery.utils.log import get_task_logger
from gvapgsql import settings
from psycopg2 import connect from psycopg2 import connect
from psycopg2.extensions import ISQLQuote from psycopg2.extensions import ISQLQuote
from pgsqltasks import settings
_LOGGER = get_task_logger(__name__) _LOGGER = get_task_logger(__name__)
@ -56,7 +53,7 @@ def _get_connection():
port=settings.GVAPGSQL_DBADMIN_PORT, port=settings.GVAPGSQL_DBADMIN_PORT,
user=settings.GVAPGSQL_DBADMIN_USER, user=settings.GVAPGSQL_DBADMIN_USER,
password=settings.GVAPGSQL_DBADMIN_PASSWORD, password=settings.GVAPGSQL_DBADMIN_PASSWORD,
database='postgres', database="postgres",
) )
@ -77,11 +74,10 @@ def create_pgsql_user(username, password):
""" """
CREATE USER %(username)s WITH PASSWORD %(password)s CREATE USER %(username)s WITH PASSWORD %(password)s
""", """,
{'username': Ident(username), 'password': password} {"username": Ident(username), "password": password},
) )
@shared_task @shared_task
def set_pgsql_userpassword(username, password): def set_pgsql_userpassword(username, password):
""" """
@ -99,7 +95,7 @@ def set_pgsql_userpassword(username, password):
""" """
ALTER ROLE %(username)s WITH PASSWORD %(password)s ALTER ROLE %(username)s WITH PASSWORD %(password)s
""", """,
{'username': Ident(username), 'password': password} {"username": Ident(username), "password": password},
) )
@ -119,7 +115,7 @@ def delete_pgsql_user(username):
""" """
DROP ROLE %(username)s DROP ROLE %(username)s
""", """,
{'username': Ident(username)} {"username": Ident(username)},
) )
@ -142,7 +138,7 @@ def create_pgsql_database(dbname, username):
CREATE DATABASE %(dbname)s OWNER %(username)s CREATE DATABASE %(dbname)s OWNER %(username)s
TEMPLATE template0 ENCODING 'UTF8' TEMPLATE template0 ENCODING 'UTF8'
""", """,
{'dbname': Ident(dbname), 'username': Ident(username)} {"dbname": Ident(dbname), "username": Ident(username)},
) )
@ -163,5 +159,5 @@ def delete_pgsql_database(dbname):
""" """
DROP DATABASE %(dbname)s DROP DATABASE %(dbname)s
""", """,
{'dbname': Ident(dbname)} {"dbname": Ident(dbname)},
) )