-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from ImperialCollegeLondon/ers_msg
ERS Kafka message topic
- Loading branch information
Showing
7 changed files
with
94 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Django management command to populate Kafka messages into application database.""" | ||
|
||
from argparse import ArgumentParser | ||
from datetime import UTC, datetime | ||
from typing import Any | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from ...models import DruncMessage | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Store Kafka messages in the database.""" | ||
|
||
help = __doc__ | ||
|
||
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") | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 5.1.2 on 2024-10-22 16:26 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('main', '0003_druncmessage'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='druncmessage', | ||
name='topic', | ||
field=models.CharField(default='', max_length=255), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters