Skip to content

Commit

Permalink
Render messages from database.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturner246 committed Oct 10, 2024
1 parent ceaebce commit 028e6a5
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions process_manager/views/partials.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from django.db import transaction
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from druncschema.process_manager_pb2 import (
ProcessInstance,
)
from druncschema.process_manager_pb2 import ProcessInstance

from main.models import DruncMessage

from ..process_manager_interface import get_session_info
from ..tables import ProcessTable
Expand Down Expand Up @@ -62,13 +62,11 @@ def process_table(request: HttpRequest) -> HttpResponse:

@login_required
def messages(request: HttpRequest) -> HttpResponse:
"""Renders and pops Kafka messages from the user's session."""
"""Renders Kafka messages from the database."""
with transaction.atomic():
# atomic to avoid race condition with kafka consumer
messages = request.session.load().get("messages", [])
request.session.pop("messages", [])
request.session.save()

messages = [
f"{msg.timestamp}: {msg.message}" for msg in DruncMessage.objects.all()
]
return render(
request=request,
context=dict(messages=messages[::-1]),
Expand Down

0 comments on commit 028e6a5

Please sign in to comment.