Skip to content

Commit b9170e6

Browse files
committed
Change error handling
1 parent 2eda462 commit b9170e6

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ services:
6868
nats-indexer:
6969
deploy:
7070
replicas: 1
71-
restart: always
7271
image: ghcr.io/heussd/nats-news-analysis/nats-indexer:latest
7372
environment:
7473
- 'NATS_URL=nats-server:4222'

python/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
pub-article:
2-
nats pub article-urls "{\"url\": \"https://www.tagesschau.de/ausland/indien-satellit-102.html\"}"
2+
nats pub article-urls "{\"url\": \"https://www.tagesschau.de/ausland/indien-satellit-102.html\"}"
3+
4+
5:
5+
$(MAKE) pub-article
6+
$(MAKE) pub-article
7+
$(MAKE) pub-article
8+
$(MAKE) pub-article
9+
$(MAKE) pub-article

python/ai_search.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import requests
77

88

9-
def add(searchDocs: List[dict]):
9+
def add(searchDocs: List[dict]) -> bool:
1010
if len(searchDocs) == 0:
1111
print("No documents to add.")
1212
return
@@ -22,9 +22,12 @@ def add(searchDocs: List[dict]):
2222
data=json.dumps(data, cls=NumpyEncoder),
2323
)
2424

25-
res.raise_for_status()
2625
if res.status_code == 200:
2726
print(f"{len(searchDocs)} documents added to the search index successfully.")
27+
return True
28+
else:
29+
print(f"Failed to add documents to the search index. Status code: {res.status_code}, Status text: {res.text}")
30+
return False
2831

2932

3033
def search(query: str):

python/nats-indexer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ async def process(msgs: List[nats.aio.msg.Msg]):
2222
url=json_data["url"],
2323
))
2424
prepared_search_docs = prepare(jsonmsgs)
25-
add(prepared_search_docs)
25+
if not add(prepared_search_docs):
26+
raise Exception("Failed to add documents to AI search index")
2627

2728

2829
async def run():

0 commit comments

Comments
 (0)