mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Merge pull request #1423 from Jngai/queuedjobpatch
retry queued job patch
This commit is contained in:
commit
35bbd2a492
5 changed files with 29 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ Huginn::Application.routes.draw do
|
|||
collection do
|
||||
delete :destroy_failed
|
||||
delete :destroy_all
|
||||
post :retry_queued
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue