queue
This commit is contained in:
parent
793251e2bc
commit
95ef8a7821
@ -1,3 +1,5 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
import pika
|
import pika
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
from pika.adapters.utils.connection_workflow import AMQPConnectorException
|
from pika.adapters.utils.connection_workflow import AMQPConnectorException
|
||||||
@ -16,16 +18,19 @@ def send_testing(solution):
|
|||||||
channel.basic_publish(
|
channel.basic_publish(
|
||||||
exchange="",
|
exchange="",
|
||||||
routing_key="test",
|
routing_key="test",
|
||||||
body=bytes(str(solution.id), encoding="utf-8"),
|
body=json.dumps({"id": solution.id}).encode('utf-8'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MessagingSupport(BaseCommand):
|
class MessagingSupport(BaseCommand):
|
||||||
queue_name = None
|
queue_name = None
|
||||||
|
|
||||||
def consume(self, ch, method, properties, body):
|
def process(self, payload: dict):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def consume(self, ch, method, properties, body):
|
||||||
|
self.process(json.loads(body.decode('utf-8')))
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
if self.queue_name is None:
|
if self.queue_name is None:
|
||||||
raise NotImplementedError("Queue name must be declared")
|
raise NotImplementedError("Queue name must be declared")
|
||||||
|
@ -5,5 +5,5 @@ class Command(MessagingSupport):
|
|||||||
help = "starts file generator"
|
help = "starts file generator"
|
||||||
queue_name = "files"
|
queue_name = "files"
|
||||||
|
|
||||||
def consume(self, ch, method, properties, body):
|
def process(self, payload: dict):
|
||||||
...
|
...
|
||||||
|
@ -10,8 +10,8 @@ class Command(MessagingSupport):
|
|||||||
help = "Tests solution"
|
help = "Tests solution"
|
||||||
queue_name = "test"
|
queue_name = "test"
|
||||||
|
|
||||||
def consume(self, ch, method, properties, body):
|
def process(self, payload: dict):
|
||||||
id = int(str(body, encoding="utf-8"))
|
id = payload['id']
|
||||||
print(f"Received id {id}")
|
print(f"Received id {id}")
|
||||||
solution = Solution.objects.get(id=id)
|
solution = Solution.objects.get(id=id)
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user