Skip to content

Commit

Permalink
fix: content not saving
Browse files Browse the repository at this point in the history
  • Loading branch information
derkweijers committed Jan 26, 2024
1 parent 2d1ef91 commit 7f6f585
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
25 changes: 11 additions & 14 deletions consumer/mq_consumer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import json
import logging
from pprint import pprint

import pika
from django.conf import settings

from consumer.serializers.importer import ArticleImportSerializer, BlogImportSerializer
from consumer.serializers.importer.report import ReportImportSerializer
from consumer.serializers import (
ArticleImportSerializer,
BlogImportSerializer,
ReportImportSerializer,
)


class MqConsumer:
Expand All @@ -23,13 +27,15 @@ def _message_callback(
# Decode the message
message = json.loads(body)

pprint(message)

match message["type"]:
case "article":
self._save_article(message["data"])
self._save_data(ArticleImportSerializer, message["data"])
case "blog":
self._save_blog(message["data"])
self._save_data(BlogImportSerializer, message["data"])
case "report":
self._save_report(message["data"])
self._save_data(ReportImportSerializer, message["data"])
case _:
channel.basic_nack(
delivery_tag=method_frame.delivery_tag, requeue=False
Expand Down Expand Up @@ -62,15 +68,6 @@ def _save_data(
f"Saved {serializer_class.__name__} with title: {serializer.validated_data['title']}"
)

def _save_article(self, data: dict[str, str | dict[str, str | int]]) -> None:
self._save_data(ArticleImportSerializer, data)

def _save_blog(self, data: dict[str, str | dict[str, str | int]]) -> None:
self._save_data(BlogImportSerializer, data)

def _save_report(self, data: dict[str, str | dict[str, str | int]]) -> None:
self._save_data(ReportImportSerializer, data)

def consume(self) -> None:
self.connection = pika.BlockingConnection(
parameters=pika.ConnectionParameters(
Expand Down
5 changes: 5 additions & 0 deletions consumer/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from consumer.serializers.article import ArticleImportSerializer
from consumer.serializers.blog import BlogImportSerializer
from consumer.serializers.report import ReportImportSerializer

__all__ = ["ArticleImportSerializer", "BlogImportSerializer", "ReportImportSerializer"]
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions consumer/serializers/importer/__init__.py

This file was deleted.

File renamed without changes.

0 comments on commit 7f6f585

Please sign in to comment.