diff --git a/SprintLib/queue.py b/SprintLib/queue.py index 670bcbe..20ad01c 100644 --- a/SprintLib/queue.py +++ b/SprintLib/queue.py @@ -1,3 +1,5 @@ +import json + import pika from django.core.management import BaseCommand from pika.adapters.utils.connection_workflow import AMQPConnectorException @@ -16,16 +18,19 @@ def send_testing(solution): channel.basic_publish( exchange="", routing_key="test", - body=bytes(str(solution.id), encoding="utf-8"), + body=json.dumps({"id": solution.id}).encode('utf-8'), ) class MessagingSupport(BaseCommand): queue_name = None - def consume(self, ch, method, properties, body): + def process(self, payload: dict): raise NotImplementedError + def consume(self, ch, method, properties, body): + self.process(json.loads(body.decode('utf-8'))) + def handle(self, *args, **options): if self.queue_name is None: raise NotImplementedError("Queue name must be declared") diff --git a/daemons/management/commands/file_generator.py b/daemons/management/commands/file_generator.py index ee55b4f..a94b33b 100644 --- a/daemons/management/commands/file_generator.py +++ b/daemons/management/commands/file_generator.py @@ -5,5 +5,5 @@ class Command(MessagingSupport): help = "starts file generator" queue_name = "files" - def consume(self, ch, method, properties, body): - ... \ No newline at end of file + def process(self, payload: dict): + ... diff --git a/daemons/management/commands/receive.py b/daemons/management/commands/receive.py index d98cd95..c09ca11 100644 --- a/daemons/management/commands/receive.py +++ b/daemons/management/commands/receive.py @@ -10,8 +10,8 @@ class Command(MessagingSupport): help = "Tests solution" queue_name = "test" - def consume(self, ch, method, properties, body): - id = int(str(body, encoding="utf-8")) + def process(self, payload: dict): + id = payload['id'] print(f"Received id {id}") solution = Solution.objects.get(id=id) try: