Skip to content
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

changes server and worker #80

Merged
merged 50 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
63d84a0
changes server and worker
cyri113 Jun 28, 2024
204ad4f
missing document start "---" (document-start)
cyri113 Jun 28, 2024
e100dd2
add .yamllint
cyri113 Jun 28, 2024
f890047
fix imports (isort)
cyri113 Jun 28, 2024
37e4733
black lint
cyri113 Jun 28, 2024
2630edb
isort fix
cyri113 Jun 28, 2024
9d48fcc
isort tasks
cyri113 Jun 28, 2024
8bcecb9
black server
cyri113 Jun 28, 2024
cda1315
disabled isort
cyri113 Jun 28, 2024
b3a90e5
fix worker
cyri113 Jun 28, 2024
0a5ef7c
Update Dockerfile
cyri113 Jun 28, 2024
9726f9d
fix worker
cyri113 Jun 28, 2024
77576ad
move traceloop to celery
cyri113 Jun 28, 2024
c1f61c8
use worker_process_init
cyri113 Jun 28, 2024
75e784c
black
cyri113 Jun 28, 2024
cfbf9f7
log trace init
cyri113 Jun 28, 2024
7bb0979
test traceloop
cyri113 Jun 28, 2024
d2fb665
formatting
cyri113 Jun 28, 2024
397164f
reformat
cyri113 Jun 28, 2024
f206fad
fix decorator?
cyri113 Jun 28, 2024
375cd23
flip tasks
cyri113 Jun 28, 2024
d857289
remove @task
cyri113 Jun 28, 2024
eae7999
init tracing
cyri113 Jun 28, 2024
e23dcad
fix format
cyri113 Jun 28, 2024
6c2d75b
init tracing?
cyri113 Jun 28, 2024
3e43510
more logs
cyri113 Jun 28, 2024
6de2522
move trace to utils
cyri113 Jun 28, 2024
d79e553
use worker_init
cyri113 Jun 28, 2024
769a75d
fix worker init
cyri113 Jun 28, 2024
146fa37
fix
cyri113 Jun 28, 2024
e47cc7f
fix init args
cyri113 Jun 28, 2024
0ecd970
add alot of signals
cyri113 Jun 28, 2024
ed3bd01
remove unrequired signals
cyri113 Jun 28, 2024
b0f1533
fix
cyri113 Jun 28, 2024
0974900
worker_process_init
cyri113 Jun 28, 2024
dd2e9f8
handlers
cyri113 Jun 28, 2024
df24bfb
handlers
cyri113 Jun 28, 2024
f1b0cf9
worker ready
cyri113 Jun 28, 2024
337a386
task_prerun
cyri113 Jun 28, 2024
622f64d
removed unused imports
cyri113 Jun 29, 2024
7ce28ab
Delete coverage/lcov.info
cyri113 Jun 29, 2024
34dac4f
imp traceloop
cyri113 Jun 29, 2024
3b3814b
remove unused import
cyri113 Jun 29, 2024
9621d44
isort celery
cyri113 Jun 29, 2024
00d1369
isort tasks.py
cyri113 Jun 29, 2024
2b7dec7
black tasks.py
cyri113 Jun 29, 2024
10e08d3
black tasks.py
cyri113 Jun 29, 2024
1eb0355
black tasks.py
cyri113 Jun 29, 2024
d565495
fix: isort linter issues!
amindadgar Jun 29, 2024
50d95e8
remove log on finished
cyri113 Jun 29, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

name: Production CI/CD Pipeline

on:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/start.staging.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

name: Staging CI/CD Pipeline

on: pull_request
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/
coverage/

# Translations
*.mo
Expand Down
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
brackets:
forbid: false
min-spaces-inside: 1
max-spaces-inside: 1
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN chmod +x docker-entrypoint.sh
CMD ["./docker-entrypoint.sh"]

FROM base AS prod
CMD ["python3", "-m", "celery", "-A", "celery_app.server", "worker", "-l", "INFO"]
CMD ["celery", "-A", "worker", "worker", "-l", "INFO"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to CMD instruction needs correction.

The CMD instruction has been updated to "celery", "-A", "worker", "worker", "-l", "INFO". However, based on the summary, it seems the intention was to use "celery", "-A", "tasks", "worker", "-l", "INFO".

- CMD ["celery", "-A", "worker", "worker", "-l", "INFO"]
+ CMD ["celery", "-A", "tasks", "worker", "-l", "INFO"]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CMD ["celery", "-A", "worker", "worker", "-l", "INFO"]
CMD ["celery", "-A", "tasks", "worker", "-l", "INFO"]

5 changes: 2 additions & 3 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
version: "3.9"
---

services:
server:
build:
context: .
target: prod
dockerfile: Dockerfile
command: python3 server.py
worker:
build:
context: .
target: prod
dockerfile: Dockerfile
command: python3 worker.py
17 changes: 11 additions & 6 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.9"
---

services:
app:
Expand Down Expand Up @@ -55,7 +55,7 @@ services:
- NEO4J_PLUGINS=["apoc", "graph-data-science"]
- NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*
healthcheck:
test: ["CMD", "wget", "http://localhost:7474"]
test: [ "CMD", "wget", "http://localhost:7474" ]
interval: 1m30s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the health check command for Neo4j.

The health check uses wget to ensure Neo4j is running by checking the HTTP response from its web interface. This is a straightforward and effective method to verify the service is up. However, consider using --spider option with wget to avoid downloading content unnecessarily.

- test: [ "CMD", "wget", "http://localhost:7474" ]
+ test: [ "CMD", "wget", "--spider", "http://localhost:7474" ]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test: [ "CMD", "wget", "http://localhost:7474" ]
test: [ "CMD", "wget", "--spider", "http://localhost:7474" ]

timeout: 10s
retries: 2
Expand All @@ -77,7 +77,7 @@ services:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=pass
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
test: [ "CMD-SHELL", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5
Expand Down Expand Up @@ -105,12 +105,17 @@ services:
qdrant-healthcheck:
restart: always
image: curlimages/curl:latest
entrypoint: ["/bin/sh", "-c", "--", "while true; do sleep 30; done;"]
entrypoint:
[
"/bin/sh",
"-c",
"--",
"while true; do sleep 30; done;"
]
depends_on:
- qdrant
healthcheck:
test: ["CMD", "curl", "-f", "http://qdrant:6333/readyz"]
test: [ "CMD", "curl", "-f", "http://qdrant:6333/readyz" ]
interval: 10s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize the health check command for Qdrant.

The health check command for Qdrant uses curl to check the service readiness. Consider adding a retry mechanism in the curl command itself for more robust error handling.

- test: [ "CMD", "curl", "-f", "http://qdrant:6333/readyz" ]
+ test: [ "CMD", "curl", "-f", "--retry 5", "http://qdrant:6333/readyz" ]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test: [ "CMD", "curl", "-f", "http://qdrant:6333/readyz" ]
test: [ "CMD", "curl", "-f", "--retry 5", "http://qdrant:6333/readyz" ]

timeout: 2s
retries: 5

2 changes: 1 addition & 1 deletion worker.py → server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any

import backoff
from celery_app.tasks import ask_question_auto_search
from pika.exceptions import ConnectionClosedByBroker
from tc_messageBroker import RabbitMQ
from tc_messageBroker.rabbit_mq.event import Event
Expand All @@ -13,6 +12,7 @@
from tc_messageBroker.rabbit_mq.queue import Queue
from utils.credentials import load_rabbitmq_credentials
from utils.fetch_community_id import fetch_community_id_by_guild_id
from worker.tasks import ask_question_auto_search


def query_llm(recieved_data: dict[str, Any]):
Expand Down
16 changes: 16 additions & 0 deletions utils/traceloop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging
import os

from dotenv import load_dotenv
from traceloop.sdk import Traceloop

load_dotenv()


def init_tracing():
otel_endpoint = os.getenv("TRACELOOP_BASE_URL")
if not otel_endpoint:
logging.error("TRACELOOP_BASE_URL is not set.")
return
Traceloop.init(app_name="hivemind-worker", api_endpoint=otel_endpoint)
logging.info("Traceloop initialized.")
File renamed without changes.
11 changes: 9 additions & 2 deletions celery_app/server.py → worker/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@
host = rabbit_creds["host"]
port = rabbit_creds["port"]

app = Celery("celery_app/tasks", broker=f"pyamqp://{user}:{password}@{host}:{port}//")
app.autodiscover_tasks(["celery_app"])
app = Celery(
"tasks",
broker=f"pyamqp://{user}:{password}@{host}:{port}//",
include=["worker.tasks"],
)


if __name__ == "__main__":
app.start()
21 changes: 12 additions & 9 deletions celery_app/tasks.py → worker/tasks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import gc
import json
import logging
import os
from typing import Any

from celery.signals import task_postrun
from celery_app.server import app
from celery_app.utils.fire_event import job_send
from dotenv import load_dotenv
from celery.signals import task_postrun, task_prerun
from subquery import query_multiple_source
from tc_messageBroker.rabbit_mq.event import Event
from tc_messageBroker.rabbit_mq.payload.discord_bot.base_types.interaction_callback_data import (
Expand All @@ -18,8 +14,10 @@
)
from tc_messageBroker.rabbit_mq.payload.payload import Payload
from tc_messageBroker.rabbit_mq.queue import Queue
from traceloop.sdk import Traceloop
from utils.data_source_selector import DataSourceSelector
from utils.traceloop import init_tracing
from worker.celery import app
from worker.utils.fire_event import job_send


@app.task
Expand All @@ -46,9 +44,6 @@ def ask_question_auto_search(
- `date`
- `content`: which is the `ChatInputCommandInteraction` as a dictionary
"""
load_dotenv()
otel_endpoint = os.getenv("TRACELOOP_BASE_URL")
Traceloop.init(app_name="hivemind-server", api_endpoint=otel_endpoint)

prefix = f"COMMUNITY_ID: {community_id} | "
logging.info(f"{prefix}Processing question!")
Expand Down Expand Up @@ -109,6 +104,7 @@ def ask_question_auto_search(
queue_name=Queue.DISCORD_BOT,
content=response_payload,
)
logging.info("FINISHED JOB")
except Exception as exp:
logging.error(f"Exception {exp} | during processing the question {question}")
response_payload = Payload.DISCORD_BOT.INTERACTION_RESPONSE.Edit(
Expand All @@ -122,6 +118,13 @@ def ask_question_auto_search(
queue_name=Queue.DISCORD_BOT,
content=response_payload,
)
logging.info("FINISHED JOB WITH EXCEPTION")


@task_prerun.connect
def task_prerun_handler(sender=None, **kwargs):
# Initialize Traceloop for LLM
init_tracing()


@task_postrun.connect
Expand Down
File renamed without changes.
File renamed without changes.
Loading