Skip to content

Commit

Permalink
Delete unused cfg options
Browse files Browse the repository at this point in the history
Also revise cancel/delete mechanism
Closes: Parallels#293 and Parallels#230
Small fix
  • Loading branch information
coolhacker committed Dec 17, 2019
1 parent d606972 commit cb7729d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 47 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ Options:
--poll-interval, --interval INTEGER
Refresh interval in ms
--extra-path TEXT Append specified directories to sys.path
--web-background TEXT Background of the web interface
--delete-jobs TEXT Delete jobs instead of cancel
--debug / --normal Enter DEBUG mode
-v, --verbose Enable verbose logging
--help Show this message and exit.
Expand Down
20 changes: 14 additions & 6 deletions rq_dashboard/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,17 @@ def make_flask_app(config, username, password, url_prefix, compatibility_mode=Tr
help="Append specified directories to sys.path",
)
@click.option(
"--web-background", default="black", help="Background of the web interface"
"--web-background",
default=None,
hidden=True,
help="[DEPRECATED] Background of the web interface",
)
@click.option(
"--delete-jobs",
default=None,
hidden=True,
help="[DEPRECATED] Delete jobs instead of cancel",
)
@click.option("--delete-jobs", default=False, help="Delete jobs instead of cancel")
@click.option("--debug/--normal", default=False, help="Enter DEBUG mode")
@click.option(
"-v", "--verbose", is_flag=True, default=False, help="Enable verbose logging"
Expand Down Expand Up @@ -200,12 +208,12 @@ def run(
app.config["DEPRECATED_OPTIONS"].append("--redis-sentinels")
if redis_master_name:
app.config["DEPRECATED_OPTIONS"].append("--redis-master-name")
if web_background:
app.config["DEPRECATED_OPTIONS"].append("--web-background")
if delete_jobs is not None:
app.config["DEPRECATED_OPTIONS"].append("--delete-jobs")
if poll_interval:
app.config["RQ_DASHBOARD_POLL_INTERVAL"] = poll_interval
if web_background:
app.config["RQ_DASHBOARD_WEB_BACKGROUND"] = web_background
if delete_jobs:
app.config["RQ_DASHBOARD_DELETE_JOBS"] = delete_jobs
# Conditionally disable Flask console messages
# See: https://stackoverflow.com/questions/14888799
log = logging.getLogger("werkzeug")
Expand Down
2 changes: 1 addition & 1 deletion rq_dashboard/templates/rq_dashboard/job.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2><strong>Job ID</strong>: {{ id }}</h2>

<span class="col-2">
<button id="requeue-job-btn" class="btn btn-outline-warning btn-sm">Requeue</button>
<button id="cancel-job-btn" class="btn btn-outline-danger btn-sm">Cancel</button>
<button id="delete-job-btn" class="btn btn-outline-danger btn-sm">Delete</button>
</span>
</div>
<div id="job-data" class="row"></div>
Expand Down
2 changes: 1 addition & 1 deletion rq_dashboard/templates/rq_dashboard/jobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<% if (d.exc_info) { %>
<a href="#" data-role="requeue-job-btn" class="btn btn-outline-warning btn-sm btn-block">Requeue</a>
<% } %>
<a href="#" data-role="cancel-job-btn" class="btn btn-outline-danger btn-sm">Cancel</a>
<a href="#" data-role="delete-job-btn" class="btn btn-outline-danger btn-sm">Delete</a>
</td>
</tr>
</script>
Expand Down
2 changes: 1 addition & 1 deletion rq_dashboard/templates/rq_dashboard/scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var url_for = function(name, param) {
else if (name == 'queues_view') { url += {{ current_instance|tojson|safe }} + '/view/queues'; }
else if (name == 'workers') { url += {{ current_instance|tojson|safe }} + '/data/workers.json'; }
else if (name == 'workers_view') { url += {{ current_instance|tojson|safe }} + '/view/workers'; }
else if (name == 'cancel_job') { url += 'job/' + encodeURIComponent(param) + '/cancel'; }
else if (name == 'delete_job') { url += 'job/' + encodeURIComponent(param) + '/delete'; }
else if (name == 'requeue_job') { url += 'job/' + encodeURIComponent(param) + '/requeue'; }
return url;
};
Expand Down
6 changes: 3 additions & 3 deletions rq_dashboard/templates/rq_dashboard/scripts/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
$('#refresh-button').click(reload_job_info);
});

$("#cancel-job-btn").click(function() {
var url = url_for('cancel_job', job_id);
$("#delete-job-btn").click(function() {
var url = url_for('delete_job', job_id);

modalConfirm('cancel job', function() {
modalConfirm('delete job', function() {
$.post(url);
$(location).attr("href", '/view/queues');
});
Expand Down
8 changes: 4 additions & 4 deletions rq_dashboard/templates/rq_dashboard/scripts/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@
return false;
});

// Enable the AJAX behaviour of the cancel button
$tbody.on('click', '[data-role=cancel-job-btn]', function(e) {
// Enable the AJAX behaviour of the delete button
$tbody.on('click', '[data-role=delete-job-btn]', function(e) {
e.preventDefault();
e.stopPropagation();

var $this = $(this),
$row = $this.parents('tr'),
job_id = $row.data('job-id'),
url = url_for('cancel_job', job_id);
url = url_for('delete_job', job_id);

modalConfirm('cancel job', function() {
modalConfirm('delete job', function() {
$.post(url, function(data) {
$row.fadeOut('fast', function() { $row.remove(); });
});
Expand Down
48 changes: 19 additions & 29 deletions rq_dashboard/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
VERSION as rq_version,
Queue,
Worker,
cancel_job,
pop_connection,
push_connection,
requeue_job,
Expand All @@ -61,9 +60,6 @@

@blueprint.before_app_first_request
def setup_rq_connection():
# It's the only place where we can safely define default value for web background
# since It is used in template
current_app.config.setdefault("RQ_DASHBOARD_WEB_BACKGROUND", "#f8f9fa")
# we need to do It here instead of cli, since It may be embeded
upgrade_config(current_app)
# Getting Redis connection parameters for RQ
Expand Down Expand Up @@ -263,9 +259,9 @@ def queues_overview(instance_number):
rq_dashboard_version=rq_dashboard_version,
rq_version=rq_version,
active_tab="queues",
deprecation_options_usage=current_app.config.get("DEPRECATED_OPTIONS")
if current_app.config.get("DEPRECATED_OPTIONS")
else False,
deprecation_options_usage=current_app.config.get(
"DEPRECATED_OPTIONS", False
),
)
)
r.headers.set("Cache-Control", "no-store")
Expand All @@ -284,9 +280,9 @@ def workers_overview(instance_number):
rq_dashboard_version=rq_dashboard_version,
rq_version=rq_version,
active_tab="workers",
deprecation_options_usage=current_app.config.get("DEPRECATED_OPTIONS")
if current_app.config.get("DEPRECATED_OPTIONS")
else False,
deprecation_options_usage=current_app.config.get(
"DEPRECATED_OPTIONS", False
),
)
)
r.headers.set("Cache-Control", "no-store")
Expand Down Expand Up @@ -324,9 +320,9 @@ def jobs_overview(instance_number, queue_name, registry_name, per_page, page):
rq_dashboard_version=rq_dashboard_version,
rq_version=rq_version,
active_tab="jobs",
deprecation_options_usage=current_app.config.get("DEPRECATED_OPTIONS")
if current_app.config.get("DEPRECATED_OPTIONS")
else False,
deprecation_options_usage=current_app.config.get(
"DEPRECATED_OPTIONS", False
),
)
)
r.headers.set("Cache-Control", "no-store")
Expand All @@ -345,26 +341,20 @@ def job_view(instance_number, job_id):
rq_url_prefix="/",
rq_dashboard_version=rq_dashboard_version,
rq_version=rq_version,
deprecation_options_usage=current_app.config.get("DEPRECATED_OPTIONS")
if current_app.config.get("DEPRECATED_OPTIONS")
else False,
deprecation_options_usage=current_app.config.get(
"DEPRECATED_OPTIONS", False
),
)
)
r.headers.set("Cache-Control", "no-store")
return r


@blueprint.route("/job/<job_id>/cancel", methods=["POST"])
@blueprint.route("/job/<job_id>/delete", methods=["POST"])
@jsonify
def cancel_job_view(job_id):
def delete_job_view(job_id):
job = Job.fetch(job_id)
if job.is_queued:
if current_app.config.get("RQ_DASHBOARD_DELETE_JOBS", False):
job.delete()
else:
cancel_job(job_id)
else:
job.delete()
job.delete()
return dict(status="OK")


Expand Down Expand Up @@ -395,19 +385,19 @@ def empty_queue(queue_name, registry_name):
elif registry_name == "failed":
ids = FailedJobRegistry(queue_name).get_job_ids()
for id in ids:
cancel_job_view(id)
delete_job_view(id)
elif registry_name == "deferred":
ids = DeferredJobRegistry(queue_name).get_job_ids()
for id in ids:
cancel_job_view(id)
delete_job_view(id)
elif registry_name == "started":
ids = StartedJobRegistry(queue_name).get_job_ids()
for id in ids:
cancel_job_view(id)
delete_job_view(id)
elif registry_name == "finished":
ids = FinishedJobRegistry(queue_name).get_job_ids()
for id in ids:
cancel_job_view(id)
delete_job_view(id)
return dict(status="OK")


Expand Down

0 comments on commit cb7729d

Please sign in to comment.