From 0a23909ac89e7fc5c4543330059d75769adf228f Mon Sep 17 00:00:00 2001 From: Tyler Knappe Date: Thu, 21 May 2015 03:55:47 +0000 Subject: [PATCH] Ajaxify retry and remove links in Failure queue. Prevent expensive page reloads when removing or retrying links. --- .../resque_web/failures_controller.rb | 2 +- .../resque_web/failures/_failed_job.html.erb | 6 +-- app/views/resque_web/failures/index.html.erb | 44 ++++++++++++++++++- test/functional/failures_controller_test.rb | 2 +- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/controllers/resque_web/failures_controller.rb b/app/controllers/resque_web/failures_controller.rb index 00a7696..e25481c 100644 --- a/app/controllers/resque_web/failures_controller.rb +++ b/app/controllers/resque_web/failures_controller.rb @@ -12,7 +12,7 @@ def index # remove an individual job from the failure queue def destroy Resque::Failure.remove(params[:id]) - redirect_to failures_path(redirect_params) + render json: {:success => true}, status: 200 end # destroy all jobs from the failure queue diff --git a/app/views/resque_web/failures/_failed_job.html.erb b/app/views/resque_web/failures/_failed_job.html.erb index 7ea5073..8d59c8d 100644 --- a/app/views/resque_web/failures/_failed_job.html.erb +++ b/app/views/resque_web/failures/_failed_job.html.erb @@ -1,4 +1,4 @@ -
  • +
  • <% if job.nil? %>
    Error
    @@ -17,9 +17,9 @@ <% else %>
    - <%= link_to "Retry", retry_failure_path(:queue=>failure_queue,:id=>id), :method => :put %> + <%= link_to "Retry", retry_failure_path(:queue=>failure_queue,:id=>id), :data => {'job-id' => id }, :method => :put, :class => 'retry' %> or - <%= link_to "Remove", failure_path(:queue=>failure_queue,:id=>id), :method => :delete %> + <%= link_to "Remove", failure_path(:queue=>failure_queue,:id=>id), :data => {'job-id' => id }, :method => :delete, :class => 'remove' %>
    <% end %> diff --git a/app/views/resque_web/failures/index.html.erb b/app/views/resque_web/failures/index.html.erb index 0217a96..982f5e3 100644 --- a/app/views/resque_web/failures/index.html.erb +++ b/app/views/resque_web/failures/index.html.erb @@ -3,7 +3,6 @@ <% else %>

    Failed Jobs <%= "on '#{params[:queue]}'" if params[:queue] %> <%= "with class '#{params[:class]}'" if params[:class] %>

    <% end %> - <% unless failure_size.zero? %> <%= form_tag(destroy_all_failures_path(queue: params[:queue]), method: :delete) do %> <%= submit_tag "Clear #{failure_queue_name} Jobs", class: 'btn btn-danger', data: { confirm: "Are you sure you want to clear ALL #{failure_queue_name.downcase} jobs?" } %> @@ -21,7 +20,6 @@ <%= render partial: 'overview' %> <% else %>

    Showing <%= failure_start_at %> to <%= failure_end_at %> of <%= failure_size %> jobs

    -
      <% each_failure do |id, job| %> <%= render partial: 'failed_job', locals: { id: id, job: job } %> @@ -30,3 +28,45 @@ <%= pagination(start: failure_start_at, total: failure_size) unless params[:class] %> <% end %> + + diff --git a/test/functional/failures_controller_test.rb b/test/functional/failures_controller_test.rb index ee255c2..28762a3 100644 --- a/test/functional/failures_controller_test.rb +++ b/test/functional/failures_controller_test.rb @@ -19,7 +19,7 @@ class FailuresControllerTest < ActionController::TestCase it "deletes the failure" do Resque::Failure.expects(:remove).with('123') visit(:destroy, {:id => 123}, :method => :delete) - assert_redirected_to failures_path + assert_response(:success, '{success: true}') end end