diff --git a/autosync/.gitignore b/autosync/.gitignore new file mode 100644 index 00000000..bee8a64b --- /dev/null +++ b/autosync/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/autosync/Dockerfile b/autosync/Dockerfile new file mode 100644 index 00000000..5cde2bfe --- /dev/null +++ b/autosync/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.12 +WORKDIR /app + +COPY ./requirements.txt . +RUN pip3 install -r ./requirements.txt + +COPY . . +ENTRYPOINT ["python3", "-m", "autosync"] diff --git a/autosync/autosync/__init__.py b/autosync/autosync/__init__.py new file mode 100644 index 00000000..c0017d04 --- /dev/null +++ b/autosync/autosync/__init__.py @@ -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() diff --git a/autosync/autosync/__main__.py b/autosync/autosync/__main__.py new file mode 100644 index 00000000..85d7bc52 --- /dev/null +++ b/autosync/autosync/__main__.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +import autosync + +autosync.main() diff --git a/autosync/pyproject.toml b/autosync/pyproject.toml new file mode 100644 index 00000000..84e5d38b --- /dev/null +++ b/autosync/pyproject.toml @@ -0,0 +1,2 @@ +[tool.ruff.format] +indent-style = "tab" diff --git a/autosync/requirements.txt b/autosync/requirements.txt new file mode 100644 index 00000000..df7f4230 --- /dev/null +++ b/autosync/requirements.txt @@ -0,0 +1 @@ +pika diff --git a/shell.nix b/shell.nix index 09055872..8f4f17a6 100644 --- a/shell.nix +++ b/shell.nix @@ -5,6 +5,7 @@ aiohttp jsons watchfiles + pika ]); dotnet = with pkgs.dotnetCorePackages; combinePackages [