Skip to content

store_message

main.management.commands.store_message

Django management command to populate Kafka messages into application database.

Classes

Command

Bases: BaseCommand

Store Kafka messages in the database.

Functions
add_arguments(parser)

Add commandline options.

Source code in main/management/commands/store_message.py
def add_arguments(self, parser: ArgumentParser) -> None:
    """Add commandline options."""
    parser.add_argument("-t", "--topic", default="NO_TOPIC")
    parser.add_argument("-m", "--message", default="NO_MESSAGE")
handle(*args, **kwargs)

Command business logic.

Source code in main/management/commands/store_message.py
def handle(self, *args: Any, **kwargs: Any) -> None:  # type: ignore[misc]
    """Command business logic."""
    topic = kwargs["topic"]
    message = kwargs["message"]
    timestamp = datetime.now(tz=UTC)
    DruncMessage.objects.create(topic=topic, timestamp=timestamp, message=message)