mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add autosync rabbitmq consumer
This commit is contained in:
parent
44bb88910f
commit
6937a982d4
1
autosync/.gitignore
vendored
Normal file
1
autosync/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
8
autosync/Dockerfile
Normal file
8
autosync/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FROM python:3.12
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY ./requirements.txt .
|
||||||
|
RUN pip3 install -r ./requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
ENTRYPOINT ["python3", "-m", "autosync"]
|
35
autosync/autosync/__init__.py
Normal file
35
autosync/autosync/__init__.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
import pika
|
||||||
|
from pika import spec
|
||||||
|
from pika.adapters.blocking_connection import BlockingChannel
|
||||||
|
import pika.credentials
|
||||||
|
|
||||||
|
|
||||||
|
def callback(
|
||||||
|
ch: BlockingChannel,
|
||||||
|
method: spec.Basic.Deliver,
|
||||||
|
properties: spec.BasicProperties,
|
||||||
|
body: bytes,
|
||||||
|
):
|
||||||
|
print(f" [x] {method.routing_key}:{body}")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
connection = pika.BlockingConnection(
|
||||||
|
pika.ConnectionParameters(
|
||||||
|
host=os.environ.get("RABBITMQ_HOST", "rabbitmq"),
|
||||||
|
credentials=pika.credentials.PlainCredentials(
|
||||||
|
os.environ.get("RABBITMQ_DEFAULT_USER", "guest"),
|
||||||
|
os.environ.get("RABBITMQ_DEFAULT_PASS", "guest"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.exchange_declare(exchange="events.watched", exchange_type="topic")
|
||||||
|
result = channel.queue_declare("", exclusive=True)
|
||||||
|
queue_name = result.method.queue
|
||||||
|
channel.queue_bind(exchange="events.watched", queue=queue_name, routing_key="#")
|
||||||
|
|
||||||
|
channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
|
||||||
|
channel.start_consuming()
|
4
autosync/autosync/__main__.py
Normal file
4
autosync/autosync/__main__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import autosync
|
||||||
|
|
||||||
|
autosync.main()
|
2
autosync/pyproject.toml
Normal file
2
autosync/pyproject.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[tool.ruff.format]
|
||||||
|
indent-style = "tab"
|
1
autosync/requirements.txt
Normal file
1
autosync/requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
pika
|
Loading…
x
Reference in New Issue
Block a user