reconnecting

This commit is contained in:
Egor Matveev 2022-05-02 22:10:40 +03:00
parent ce45dd9841
commit dd857de7d2

View File

@ -3,6 +3,7 @@ import json
import pika import pika
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management import BaseCommand from django.core.management import BaseCommand
from django.db import OperationalError
from pika.adapters.utils.connection_workflow import AMQPConnectorException from pika.adapters.utils.connection_workflow import AMQPConnectorException
from Sprint import settings from Sprint import settings
@ -30,8 +31,12 @@ class MessagingSupport(BaseCommand):
def consume(self, ch, method, properties, body): def consume(self, ch, method, properties, body):
data = json.loads(body.decode('utf-8')) data = json.loads(body.decode('utf-8'))
print(f"Got {data}, processing...") print(f"Got {data}, processing...")
self.process(data) try:
print("Process finished successfully") self.process(data)
print("Process finished successfully")
except OperationalError:
print("Failed to connect to database, restarting...")
send_to_queue(self.queue_name, data)
def handle(self, *args, **options): def handle(self, *args, **options):
if self.queue_name is None: if self.queue_name is None: