Skip to content

refactored code to fix namespace issue #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
129 changes: 128 additions & 1 deletion article-search/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
.idea
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
*.iml

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
File renamed without changes.
130 changes: 0 additions & 130 deletions article-search/app/.gitignore

This file was deleted.

File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fastapi import FastAPI
from starlette import status
import service.app_service as app_service
from model.data_model import ArticleInfo, AppResponse
from config.es_config import es_obj
from appservice import app_service
from appmodel.data_model import ArticleInfo, AppResponse
from elasticservice.es_config import es_obj

app_v1 = FastAPI()

Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions article-search/src/appservice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import *
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import service.elasticsearch_service as es
import service.kafka_producer as kfk
from model.data_model import ArticleInfo
from elasticservice import es_service as es
from kafkaservice import kafka_producer as kfk
from appmodel.data_model import ArticleInfo


def save_article_info(article: ArticleInfo):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from config.es_config import es_obj, default_index
from elasticservice.es_config import es_obj, default_index


def add_doc_to_index(document_data, index_name=default_index):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from kafka import KafkaConsumer
import json

bootstrap_servers = ['localhost:9092']
bootstrap_servers = ['Win11Home.localdomain:9092']
default_topic = 'python-kafka-topic'
group_id = 'kafka-group-id'

Expand All @@ -24,7 +24,8 @@ def init_kafka_consumer(topic_name=default_topic):
_text_consumer = KafkaConsumer(topic_name, group_id=group_id, bootstrap_servers=bootstrap_servers)
_consumer = KafkaConsumer(topic_name, group_id=group_id, bootstrap_servers=bootstrap_servers,
auto_offset_reset='earliest', enable_auto_commit=True,
value_deserializer=lambda x: json.loads(x.decode('utf-8')))
value_deserializer=lambda x: json.loads(x.decode('utf-8')),
max_poll_interval_ms=1000000)
print(f"init_kafka_consumer finished")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kafka.errors import KafkaError
import config.kafka_config as kfk
import kafkaservice.kafka_config as kfk


def consume_str_message():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kafka.errors import KafkaError
import config.kafka_config as kfk
from kafkaservice import kafka_config as kfk


def on_send_success(record_metadata):
Expand Down
4 changes: 2 additions & 2 deletions article-search/app/src/main.py → article-search/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import uvicorn
import threading
from service.kafka_consumer import consume_message
from kafkaservice.kafka_consumer import consume_message


def init_app():
Expand All @@ -20,4 +20,4 @@ def init_app():
if __name__ == "__main__":
init_app()
# uvicorn article_api:app --port 8080 --reload
uvicorn.run("article_api:app_v1", host="127.0.0.1", port=8080, log_level="info")
uvicorn.run("api.article_api:app_v1", host="127.0.0.1", port=8080, log_level="info", reload=True)
Empty file.
Empty file added article-search/test/__init__.py
Empty file.