Skip to content

Commit

Permalink
Support disable deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
gnomeby committed Feb 14, 2024
1 parent 049d0ce commit 026aef1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion rq_dashboard/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def make_flask_app(config, username, password, url_prefix, compatibility_mode=Tr
hidden=True,
help="[DEPRECATED] Delete jobs instead of cancel",
)
@click.option(
"--disable-delete", is_flag=True, default=False, help="Disable delete jobs, clean up registries"
)
@click.option("--debug/--normal", default=False, help="Enter DEBUG mode")
@click.option(
"-v", "--verbose", is_flag=True, default=False, help="Enable verbose logging"
Expand All @@ -178,6 +181,7 @@ def run(
web_background,
debug,
delete_jobs,
disable_delete,
verbose,
json,
):
Expand Down Expand Up @@ -252,7 +256,9 @@ def run(
url,
)
app.config["RQ_DASHBOARD_REDIS_URL"] = url


app.config["RQ_DASHBOARD_DISABLE_DELETE"] = disable_delete

if json:
service_config.serializer = JSONSerializer

Expand Down
6 changes: 4 additions & 2 deletions rq_dashboard/templates/rq_dashboard/job.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
<span class="col-10">
<h2><strong>Job ID</strong>: {{ id }}</h2>
</span>

<span class="col-2">
<button id="requeue-job-btn" class="btn btn-outline-warning btn-sm" style="display: none">Requeue</button>
{% if enable_delete %}
<button id="delete-job-btn" class="btn btn-outline-danger btn-sm">Delete</button>
{% endif %}
</span>
</div>
<div id="job-data" class="row"></div>


<script name="job-info" type="text/template">

Expand Down
4 changes: 4 additions & 0 deletions rq_dashboard/templates/rq_dashboard/jobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
</div>

<p class="intro">
{% if enable_delete %}
<a href="{{ url_for('rq_dashboard.empty_queue', queue_name=queue.name, registry_name=registry_name) }}" id="empty-btn"
class="btn btn-outline-danger btn-sm" style="float: right" data-toggle="tooltip"
title="Remove all jobs from this queue (<b>destructive</b>)" data-html=true>Empty queue</a>
{% endif %}
{% if registry_name == 'queued' %}
<a href="{{ url_for('rq_dashboard.compact_queue', queue_name=queue.name) }}" id="compact-btn"
class="btn btn-outline-success btn-sm" style="float: right; margin-right: 8px;" data-toggle="tooltip"
Expand Down Expand Up @@ -76,7 +78,9 @@
<% if (d.exc_info) { %>
<a href="#" data-role="requeue-job-btn" class="btn btn-outline-warning btn-sm btn-block">Requeue</a>
<% } %>
{% if enable_delete %}
<a href="#" data-role="delete-job-btn" class="btn btn-outline-danger btn-sm">Delete</a>
{% endif %}
</td>
</tr>
</script>
Expand Down
11 changes: 11 additions & 0 deletions rq_dashboard/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def _wrapped(*args, **kwargs):

return _wrapped

def check_delete_enable(f):
@wraps(f)
def wrapper(*args, **kwargs):
if current_app.config.get("RQ_DASHBOARD_DISABLE_DELETE"):
return dict(status="DISABLED")
return f(*args, **kwargs)
return wrapper

def serialize_queues(instance_number, queues):
return [
Expand Down Expand Up @@ -361,6 +368,7 @@ def jobs_overview(instance_number, queue_name, registry_name, per_page, page):
deprecation_options_usage=current_app.config.get(
"DEPRECATED_OPTIONS", False
),
enable_delete=not current_app.config.get("RQ_DASHBOARD_DISABLE_DELETE"),
)
)
r.headers.set("Cache-Control", "no-store")
Expand All @@ -382,13 +390,15 @@ def job_view(instance_number, job_id):
deprecation_options_usage=current_app.config.get(
"DEPRECATED_OPTIONS", False
),
enable_delete=not current_app.config.get("RQ_DASHBOARD_DISABLE_DELETE"),
)
)
r.headers.set("Cache-Control", "no-store")
return r


@blueprint.route("/job/<job_id>/delete", methods=["POST"])
@check_delete_enable
@jsonify
def delete_job_view(job_id, registry=None):
try:
Expand Down Expand Up @@ -421,6 +431,7 @@ def requeue_all(queue_name):


@blueprint.route("/queue/<queue_name>/<registry_name>/empty", methods=["POST"])
@check_delete_enable
@jsonify
def empty_queue(queue_name, registry_name):
if registry_name == "queued":
Expand Down

0 comments on commit 026aef1

Please sign in to comment.