retry queued job patch

quick rewording

changed glyphicon

skip failed jobs locked at and using update all

spec ready as well

rm without protection modify spec

rm unnecessary lines

work on delayed job feature

fixed render json

switched from ok to success

revert render json change for other methods

checking in work

test passed

reverting render and saving a line of code

add back sign in an user

run this on github

altered format.json

rm comment

prevent ajax error head no content
This commit is contained in:
Judy Ngai 2016-03-29 14:20:34 -04:00
parent a0f886690d
commit d8df930da0
5 changed files with 29 additions and 1 deletions

View file

@ -39,6 +39,15 @@ class JobsController < ApplicationController
end
end
def retry_queued
@jobs = Delayed::Job.awaiting_retry.update_all(run_at: Time.zone.now)
respond_to do |format|
format.html { redirect_to jobs_path, notice: "Queued jobs getting retried." }
format.json { head :no_content }
end
end
def destroy_failed
Delayed::Job.where.not(failed_at: nil).delete_all

View file

@ -80,6 +80,10 @@
<span class="glyphicon glyphicon-trash"></span> Remove failed jobs
<% end %>
<%= link_to retry_queued_jobs_path, class: "btn btn-default", method: :post do %>
<span class="glyphicon glyphicon-refresh"></span> Retry queued jobs
<% end %>
<%= link_to destroy_all_jobs_path, class: "btn btn-default", method: :delete, data: { confirm: "Are you sure you want to delete ALL pending jobs for all Huginn users?" } do %>
<span class="glyphicon glyphicon-remove"></span> Remove all jobs
<% end %>

View file

@ -12,7 +12,7 @@ Delayed::Worker.logger = Rails.logger
class Delayed::Job
scope :pending, ->{ where("locked_at IS NULL AND attempts = 0") }
scope :awaiting_retry, ->{ where("failed_at IS NULL AND attempts > 0") }
scope :awaiting_retry, ->{ where("failed_at IS NULL AND attempts > 0 AND locked_at IS NULL") }
scope :failed, -> { where("failed_at IS NOT NULL") }
end

View file

@ -63,6 +63,7 @@ Huginn::Application.routes.draw do
collection do
delete :destroy_failed
delete :destroy_all
post :retry_queued
end
end

View file

@ -92,4 +92,18 @@ describe JobsController do
expect(Delayed::Job.find(@running.id)).to be
end
end
describe "POST retry_queued" do
before do
@not_running = Delayed::Job.create(run_at: Time.zone.now - 1.hour)
@not_running.update_attribute(:attempts, 1)
sign_in users(:jane)
end
it "run the queued job" do
expect(Delayed::Job.last.run_at.to_s).not_to eq(Time.zone.now.to_s)
post :retry_queued
expect(Delayed::Job.last.run_at.to_s).to eq(Time.zone.now.to_s)
end
end
end