From ff222eb543bec7f58aa933a9851a1b997f989ff1 Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 4 Apr 2020 13:58:08 +0200 Subject: [PATCH 1/7] documentation --- app.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index ce3a7ff..3162c61 100644 --- a/app.py +++ b/app.py @@ -21,19 +21,24 @@ sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10") def main(): + + # set logging preferences logging.basicConfig(filename = '', level = logging.DEBUG) + # connect to redis r = redis.Redis(host = 'localhost', port = 6379, db = 0) + # set initial consumer addresses ip_list = os.environ['INITIAL_SERVERS'].split(',') logging.debug('Get consumer list from environ at first: Done') + # get the dictionary of the currently available consumers consumer_list_redis = json.loads((r.get('consumer_list') or b'{}').decode('utf-8')) logging.debug('Get consumer list from redis at first: Done') temp_dict = { } for ip in ip_list: - try: + # request synchronization response = requests.post(f"http://{ip}/sync", json = { 'uuid': os.environ['LOCAL_UUID'] }) except requests.exceptions.ConnectionError: continue @@ -46,11 +51,13 @@ def main(): logging.debug('Update redis consumers ip list from first answers: Done') while True: logging.debug('Infinite Cycle start : Done') + # get the dictionary of the currently available consumers consumer_list_redis = json.loads((r.get('consumer_list') or b'{}').decode('utf-8')) logging.debug('Get consumer list from redis: Done') for uuid, info in consumer_list_redis.items(): ip = info['ip'] try: + # request synchronization response = requests.post(f"http://{ip}/sync", json = { 'uuid': os.environ['LOCAL_UUID'] }) except requests.exceptions.ConnectionError: continue @@ -58,11 +65,14 @@ def main(): if response.status_code == 200: temp_dict[response.json()['uuid']] = { 'ip': ip } + + # update the dictionary of the currently available consumers consumer_list_redis.update(temp_dict) r.set('consumer_list', json.dumps(consumer_list_redis).encode('utf-8')) logging.debug('Update redis consumer ip list from answers: Done') logging.debug('Waiting for next turn') + # wait for the next update time time.sleep(30) From 4962c3e33e020729e7fd8a12ba7277f7177645b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 4 Apr 2020 18:58:19 +0200 Subject: [PATCH 2/7] sphinx generate with ci --- .drone.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.drone.yml b/.drone.yml index 47daeb8..aa1e39e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,6 +30,13 @@ steps: - docker push "$DOCKER_USERNAME/consumer-scheduler" - docker push "$DOCKER_USERNAME/consumer-scheduler:$DRONE_BUILD_NUMBER" +- name: static_analysis + image: python:3 + commands: + - pip3 install Sphinx + - pip3 install -r requirements.txt + - sphinx-quickstart + - name: slack image: plugins/slack settings: From ba06b200b25e8d1193ee31846268701febf46623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 4 Apr 2020 19:08:24 +0200 Subject: [PATCH 3/7] fix drone config --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index aa1e39e..281b879 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,7 +30,7 @@ steps: - docker push "$DOCKER_USERNAME/consumer-scheduler" - docker push "$DOCKER_USERNAME/consumer-scheduler:$DRONE_BUILD_NUMBER" -- name: static_analysis +- name: build_docs image: python:3 commands: - pip3 install Sphinx From b75a6e35886e3445cd68a74705984131c470a8f7 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 7 Apr 2020 21:34:17 +0200 Subject: [PATCH 4/7] readme added --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c8ce394 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Repository for the consumer's scheduler + +Functionality: updates the database of the available consumers periodically From 44667dc23d55d5e98f598bde943a6a9fb3c880a1 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 8 Apr 2020 21:56:33 +0200 Subject: [PATCH 5/7] converted README.md to .rst format --- README.md => README.rst | 4 ++++ 1 file changed, 4 insertions(+) rename README.md => README.rst (62%) diff --git a/README.md b/README.rst similarity index 62% rename from README.md rename to README.rst index c8ce394..31ce0f0 100644 --- a/README.md +++ b/README.rst @@ -1,3 +1,7 @@ +====================== +P2P Consumer Scheduler +====================== + Repository for the consumer's scheduler Functionality: updates the database of the available consumers periodically From 270d7b531434b93b99d5b74561239a76b0d8c849 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 8 Apr 2020 22:03:12 +0200 Subject: [PATCH 6/7] added docs --- docs/Makefile | 20 +++++++++++++++ docs/conf.py | 55 +++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 23 +++++++++++++++++ docs/make.bat | 35 ++++++++++++++++++++++++++ docs/readme.rst | 1 + docs/source/app.rst | 7 ++++++ docs/source/modules.rst | 7 ++++++ 7 files changed, 148 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/readme.rst create mode 100644 docs/source/app.rst create mode 100644 docs/source/modules.rst diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..1e0445d --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,55 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'Consumer Scheduler' +copyright = '2020, GoldenPogacsa Inc.' +author = 'GoldenPogacsa Inc.' + +# The full version, including alpha/beta/rc tags +release = '0.1.0' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = [] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = [] \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..10efaa5 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +.. Consumer Scheduler documentation master file, created by + sphinx-quickstart on Wed Apr 8 21:57:33 2020. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Consumer Scheduler's documentation! +============================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + readme + source/modules + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` +* `Git repository `_ \ No newline at end of file diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..2119f51 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/readme.rst b/docs/readme.rst new file mode 100644 index 0000000..6b2b3ec --- /dev/null +++ b/docs/readme.rst @@ -0,0 +1 @@ +.. include:: ../README.rst \ No newline at end of file diff --git a/docs/source/app.rst b/docs/source/app.rst new file mode 100644 index 0000000..ceb7f40 --- /dev/null +++ b/docs/source/app.rst @@ -0,0 +1,7 @@ +app module +========== + +.. automodule:: app + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..7abee4e --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,7 @@ +consumer-scheduler +================== + +.. toctree:: + :maxdepth: 4 + + app From 928fda2fa2a91df5eaef28cb657a50208196d1b7 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 8 Apr 2020 22:07:43 +0200 Subject: [PATCH 7/7] Updated CI stuff --- .drone.yml | 27 +++++++++++++++++++++++---- docs/Dockerfile | 3 +++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 docs/Dockerfile diff --git a/.drone.yml b/.drone.yml index 281b879..8ac0dcd 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,12 +30,31 @@ steps: - docker push "$DOCKER_USERNAME/consumer-scheduler" - docker push "$DOCKER_USERNAME/consumer-scheduler:$DRONE_BUILD_NUMBER" -- name: build_docs - image: python:3 +- name: make_docs + image: python:3.8 commands: - - pip3 install Sphinx + - pip3 install Sphinx sphinx_rtd_theme - pip3 install -r requirements.txt - - sphinx-quickstart + - cd docs + - make html + +- name: build_docs + image: docker:stable-dind + volumes: + - name: dockersock + path: /var/run + environment: + DOCKER_USERNAME: + from_secret: DOCKER_USERNAME + DOCKER_PASSWORD: + from_secret: DOCKER_PASSWORD + commands: + - cd docs + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - docker build -t="$DOCKER_USERNAME/consumer-scheduler-docs" . + - docker build -t="$DOCKER_USERNAME/consumer-scheduler-docs:$DRONE_BUILD_NUMBER" . + - docker push "$DOCKER_USERNAME/consumer-scheduler-docs" + - docker push "$DOCKER_USERNAME/consumer-scheduler-docs:$DRONE_BUILD_NUMBER" - name: slack image: plugins/slack diff --git a/docs/Dockerfile b/docs/Dockerfile new file mode 100644 index 0000000..691c92e --- /dev/null +++ b/docs/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:latest + +COPY _build/html/ /usr/share/nginx/html \ No newline at end of file