Skip to content

Commit

Permalink
feat: add a way to cause celery task errors #266
Browse files Browse the repository at this point in the history
for testing the error reporting.
  • Loading branch information
Ned Batchelder committed Oct 6, 2023
1 parent 2b83ff3 commit b5b66d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions openedx_webhooks/github_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask import current_app as app
from flask import Blueprint, jsonify, render_template, request

from openedx_webhooks import celery
from openedx_webhooks.auth import get_github_session
from openedx_webhooks.debug import is_debug, print_long_json
from openedx_webhooks.info import get_bot_username
Expand Down Expand Up @@ -223,3 +224,17 @@ def generate_error():
Used to generate an error message to test error handling
"""
raise Exception("Error from generate_error")


@github_bp.route("/generate_task_error", methods=("GET",))
@requires_auth
def generate_task_error():
"""
Used to generate an error message to test error handling
"""
return queue_task(generate_task_error_task)

Check warning on line 235 in openedx_webhooks/github_views.py

View check run for this annotation

Codecov / codecov/patch

openedx_webhooks/github_views.py#L235

Added line #L235 was not covered by tests


@celery.task(bind=True)
def generate_task_error_task(_):
raise Exception("Error from generate_task_error")

Check warning on line 240 in openedx_webhooks/github_views.py

View check run for this annotation

Codecov / codecov/patch

openedx_webhooks/github_views.py#L240

Added line #L240 was not covered by tests
7 changes: 6 additions & 1 deletion openedx_webhooks/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ <h2>GitHub</h2>
</li>
<li><a href="{{ url_for("github_views.rescan_get") }}">Rescan Pull Requests</a></li>
<li><a href="{{ url_for("github_views.process_pr_get") }}">Process Pull Request</a></li>
<li><a href="{{ url_for("github_views.generate_error") }}">Generate Error</a></li>
</ul>

<h2>Other</h2>
<ul>
<li><a href="{{ url_for("github_views.generate_error") }}">Generate Immediate Error</a></li>
<li><a href="{{ url_for("github_views.generate_task_error") }}">Generate Task Error</a></li>
</ul>
</body>
</html>

0 comments on commit b5b66d2

Please sign in to comment.