1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Merge pull request #1867 from seuros/killswitch

[WEB UI] Add Kill button to retriable jobs
This commit is contained in:
Mike Perham 2014-07-28 15:49:35 -07:00
commit ca667e23cd
11 changed files with 47 additions and 7 deletions

View file

@ -316,6 +316,23 @@ module Sidekiq
end
end
##
# Place job in the dead set
def kill
raise 'Kill not available on jobs which have not failed' unless item['failed_at']
remove_job do |message|
Sidekiq.logger.info { "Killing job #{message['jid']}" }
now = Time.now.to_f
Sidekiq.redis do |conn|
conn.multi do
conn.zadd('dead', now, message)
conn.zremrangebyscore('dead', '-inf', now - DeadSet::DEAD_JOB_TIMEOUT)
conn.zremrangebyrank('dead', 0, - DeadSet::MAX_JOBS)
end
end
end
end
private
def remove_job
@ -503,6 +520,9 @@ module Sidekiq
# Allows enumeration of dead jobs within Sidekiq.
#
class DeadSet < JobSet
DEAD_JOB_TIMEOUT = 180 * 24 * 60 * 60 # 6 months
MAX_JOBS = 10_000
def initialize
super 'dead'
end

View file

@ -135,8 +135,8 @@ module Sidekiq
Sidekiq.redis do |conn|
conn.multi do
conn.zadd('dead', now, payload)
conn.zremrangebyscore('dead', '-inf', now - DEAD_JOB_TIMEOUT)
conn.zremrangebyrank('dead', 0, -MAX_JOBS)
conn.zremrangebyscore('dead', '-inf', now - DeadSet::DEAD_JOB_TIMEOUT)
conn.zremrangebyrank('dead', 0, -DeadSet::MAX_JOBS)
end
end
end

View file

@ -100,7 +100,7 @@ module Sidekiq
params['key'].each do |key|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
retry_or_delete job, params if job
retry_or_delete_or_kill job, params if job
end
redirect_with_query("#{root_path}morgue")
end
@ -118,7 +118,7 @@ module Sidekiq
post "/morgue/:key" do
halt 404 unless params['key']
job = Sidekiq::DeadSet.new.fetch(*parse_params(params['key'])).first
retry_or_delete job, params if job
retry_or_delete_or_kill job, params if job
redirect_with_query("#{root_path}morgue")
end
@ -142,7 +142,7 @@ module Sidekiq
params['key'].each do |key|
job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
retry_or_delete job, params if job
retry_or_delete_or_kill job, params if job
end
redirect_with_query("#{root_path}retries")
end
@ -160,7 +160,7 @@ module Sidekiq
post "/retries/:key" do
halt 404 unless params['key']
job = Sidekiq::RetrySet.new.fetch(*parse_params(params['key'])).first
retry_or_delete job, params if job
retry_or_delete_or_kill job, params if job
redirect_with_query("#{root_path}retries")
end
@ -227,11 +227,13 @@ module Sidekiq
private
def retry_or_delete job, params
def retry_or_delete_or_kill job, params
if params['retry']
job.retry
elsif params['delete']
job.delete
elsif params['kill']
job.kill
end
end

View file

@ -173,6 +173,17 @@ class TestWeb < Sidekiq::Test
assert_match(/#{params.first['args'][2]}/, last_response.body)
end
it 'can kill a single retry now' do
params = add_retry
post "/retries/#{job_params(*params)}", 'kill' => 'Kill'
assert_equal 302, last_response.status
assert_equal 'http://example.org/retries', last_response.header['Location']
get '/morgue'
assert_equal 200, last_response.status
assert_match(/#{params.first['args'][2]}/, last_response.body)
end
it 'can display scheduled' do
get '/scheduled'
assert_equal 200, last_response.status

View file

@ -33,6 +33,7 @@ de:
NextRetry: Nächster Versuch
RetryCount: Anzahl der Versuche
RetryNow: Jetzt erneut versuchen
Kill: Töten
LastRetry: Letzter Versuch
OriginallyFailed: Ursprünglich fehlgeschlagen
AreYouSure: Bist du sicher?

View file

@ -33,6 +33,7 @@ en: # <---- change this to your locale code
NextRetry: Next Retry
RetryCount: Retry Count
RetryNow: Retry Now
Kill: Kill
LastRetry: Last Retry
OriginallyFailed: Originally Failed
AreYouSure: Are you sure?

View file

@ -33,6 +33,7 @@ es:
NextRetry: Siguiente Intento
RetryCount: Numero de Reintentos
RetryNow: Reintentar Ahora
Kill: Matar
LastRetry: Último Reintento
OriginallyFailed: Falló Originalmente
AreYouSure: ¿Estás seguro?

View file

@ -33,6 +33,7 @@ fr:
NextRetry: Prochain essai
RetryCount: Nombre d'essais
RetryNow: Réessayer maintenant
Kill: Tuer
LastRetry: Dernier essai
OriginallyFailed: Échec originel
AreYouSure: Êtes-vous certain ?

View file

@ -33,6 +33,7 @@ it:
NextRetry: Prossimo tentativo
RetryCount: Totale tentativi
RetryNow: Riprova
Kill: Uccidere
LastRetry: Ultimo tentativo
OriginallyFailed: Primo fallimento
AreYouSure: Sei sicuro?

View file

@ -32,6 +32,7 @@ ru:
NextRetry: Следующая попытка
RetryCount: Кол-во попыток
RetryNow: Повторить сейчас
Kill: Убиваем
LastRetry: Последняя попытка
OriginallyFailed: Первый провал
AreYouSure: Вы уверены?

View file

@ -54,6 +54,7 @@
</table>
<input class="btn btn-primary btn-xs pull-left" type="submit" name="retry" value="<%= t('RetryNow') %>" />
<input class="btn btn-danger btn-xs pull-left" type="submit" name="delete" value="<%= t('Delete') %>" />
<input class="btn btn-danger btn-xs pull-left" type="submit" name="kill" value="<%= t('Kill') %>" />
</form>
<form action="<%= root_path %>retries/all/delete" method="post">