Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a replay command #334

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion fedora_messaging/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
.. _Click: http://click.pocoo.org/
"""


import errno
import importlib
import logging
Expand All @@ -30,8 +29,11 @@

import click
import pkg_resources
import requests
from twisted.internet import asyncioreactor, error

from fedora_messaging import message


try:
asyncioreactor.install()
Expand Down Expand Up @@ -91,6 +93,10 @@
"The name of the exchange to publish to. Can contain ASCII letters, "
"digits, hyphen, underscore, period, or colon."
)
_datagrepper_help = (
"The URL of the datagreeper instance to use, "
"defaults to the production environment"
)
_limit_help = "The maximum number of messages to record."


Expand Down Expand Up @@ -452,3 +458,29 @@ def record(exchange, queue_name, routing_key, app_name, limit, file):
_consume(
exchange, queue_name, routing_key, messages_recorder.collect_message, app_name
)


URL_TEMPLATE = "https://apps.fedoraproject.org/datagrepper/id?id={}&is_raw=true"


@cli.command()
@click.argument("message_id")
@click.option("--datagrepper-url", help=_datagrepper_help, default=URL_TEMPLATE)
def replay(message_id, datagrepper_url):
"""Replay a message from Datagrepper by its message ID"""
try:
message_data = _get_message(message_id, datagrepper_url)
except requests.HTTPError as e:
abompard marked this conversation as resolved.
Show resolved Hide resolved
raise click.ClickException(f"Failed to retrieve message from Datagrepper: {e}")

if message_data:
api.publish(message.load_message(message_data))
click.echo(f"Message with ID {message_id} has been successfully replayed.")


def _get_message(message_id, datagrepper_url):
"""Fetch a message by ID from Datagreeper"""
url = datagrepper_url.format(message_id)
response = requests.get(url, timeout=5)
response.raise_for_status()
return response.json()
1 change: 1 addition & 0 deletions news/332.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a replay command
Loading