From a6502e68f891219e17aa771c8271aea32f18c60b Mon Sep 17 00:00:00 2001 From: Guilherme Ceolin Date: Fri, 21 Jun 2013 23:43:06 -0300 Subject: [PATCH 1/4] Adding 'add to queue' to the list of scheduled jobs on monitor interface --- lib/sidekiq/api.rb | 11 +++++++++++ lib/sidekiq/web.rb | 9 +++++++-- web/locales/da.yml | 1 + web/locales/de.yml | 1 + web/locales/en.yml | 1 + web/locales/es.yml | 1 + web/locales/fr.yml | 1 + web/locales/it.yml | 1 + web/locales/ja.yml | 1 + web/locales/ko.yml | 1 + web/locales/nl.yml | 1 + web/locales/no.yml | 1 + web/locales/pl.yml | 1 + web/locales/pt-br.yml | 1 + web/locales/pt.yml | 1 + web/locales/ru.yml | 1 + web/views/scheduled.slim | 1 + 17 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/api.rb b/lib/sidekiq/api.rb index 8a0579b5..5b8cb3ea 100644 --- a/lib/sidekiq/api.rb +++ b/lib/sidekiq/api.rb @@ -222,6 +222,17 @@ module Sidekiq @parent.schedule(at, item) end + def add_to_queue + Sidekiq.redis do |conn| + results = conn.zrangebyscore('schedule', score, score) + conn.zremrangebyscore('schedule', score, score) + results.map do |message| + msg = Sidekiq.load_json(message) + Sidekiq::Client.push(msg) + end + end + end + def retry raise "Retry not available on jobs not in the Retry queue." unless item["failed_at"] Sidekiq.redis do |conn| diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index f51c772c..c74e10b7 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -251,9 +251,14 @@ module Sidekiq post '/scheduled' do halt 404 unless params['key'] - halt 404 unless params['delete'] + params['key'].each do |key| - Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first.delete + job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first + if params['delete'] + job.delete + elsif params['add_to_queue'] + job.add_to_queue + end end redirect "#{root_path}scheduled" end diff --git a/web/locales/da.yml b/web/locales/da.yml index 25900994..29a59796 100644 --- a/web/locales/da.yml +++ b/web/locales/da.yml @@ -24,6 +24,7 @@ da: ShowAll: Vis alle CurrentMessagesInQueue: Nuværende beskeder i %{queue} Delete: Slet + AddToQueue: Tilføj til kø AreYouSureDeleteJob: Er du sikker på at du vil slette dette job? AreYouSureDeleteQueue: Er du sikker på at du vil slette %{queue} køen? Queues: Køer diff --git a/web/locales/de.yml b/web/locales/de.yml index 72ea2a59..1129cbf9 100644 --- a/web/locales/de.yml +++ b/web/locales/de.yml @@ -24,6 +24,7 @@ de: ShowAll: Alle anzeigen CurrentMessagesInQueue: Aktuelle Nachrichten in %{queue} Delete: Löschen + AddToQueue: Add to queue AreYouSureDeleteJob: Möchtest du diesen Job wirklich löschen? AreYouSureDeleteQueue: Möchtest du %{queue} wirklich löschen? Queues: Warteschlangen diff --git a/web/locales/en.yml b/web/locales/en.yml index fcfe2d66..ead10a8f 100644 --- a/web/locales/en.yml +++ b/web/locales/en.yml @@ -26,6 +26,7 @@ en: # <---- change this to your locale code ShowAll: Show All CurrentMessagesInQueue: Current messages in %{queue} Delete: Delete + AddToQueue: Add to queue AreYouSureDeleteJob: Are you sure you want to delete this job? AreYouSureDeleteQueue: Are you sure you want to delete the %{queue} queue? Queues: Queues diff --git a/web/locales/es.yml b/web/locales/es.yml index 46407ac3..fd5c3b60 100644 --- a/web/locales/es.yml +++ b/web/locales/es.yml @@ -24,6 +24,7 @@ es: ShowAll: Mostrar Todo CurrentMessagesInQueue: Mensajes actualmente en %{queue} Delete: Eliminar + AddToQueue: Añadir a fila AreYouSureDeleteJob: ¿Estás seguro de eliminar este trabajo? AreYouSureDeleteQueue: ¿Estás seguro de eliminar la fila %{queue}? Queues: Filas diff --git a/web/locales/fr.yml b/web/locales/fr.yml index 52b926e4..572d472a 100644 --- a/web/locales/fr.yml +++ b/web/locales/fr.yml @@ -24,6 +24,7 @@ fr: ShowAll: Montrer Tout CurrentMessagesInQueue: Messages actuellement dans %{queue} Delete: Supprimer + AddToQueue: Ajouter à la liste AreYouSureDeleteJob: Êtes-vous certain de vouloir supprimer cette tâche? AreYouSureDeleteQueue: Êtes-vous certain de vouloir supprimer la file %{queue}? Queues: Queues diff --git a/web/locales/it.yml b/web/locales/it.yml index a5cab537..e87860c0 100644 --- a/web/locales/it.yml +++ b/web/locales/it.yml @@ -24,6 +24,7 @@ it: ShowAll: Mostra tutti CurrentMessagesInQueue: Messaggi in %{queue} Delete: Cancella + AddToQueue: Aggiungi a coda AreYouSureDeleteJob: Sei sicuro di voler cancellare questo lavoro? AreYouSureDeleteQueue: Sei sicuro di voler cancellare la coda %{queue}? Queues: Code diff --git a/web/locales/ja.yml b/web/locales/ja.yml index 914f15a1..0d48ce0e 100644 --- a/web/locales/ja.yml +++ b/web/locales/ja.yml @@ -25,6 +25,7 @@ ja: ShowAll: 全て見せる CurrentMessagesInQueue: %{queue}に メッセージがあります Delete: 削除 + AddToQueue: キューに追加 AreYouSureDeleteJob: このジョブを削除しますか? AreYouSureDeleteQueue: この %{queue} キューを削除しますか? Queues: キュー diff --git a/web/locales/ko.yml b/web/locales/ko.yml index 32305e73..88fd7899 100644 --- a/web/locales/ko.yml +++ b/web/locales/ko.yml @@ -25,6 +25,7 @@ ko: ShowAll: 모두 보기 CurrentMessagesInQueue: %{queue}에 대기 중인 메시지 Delete: 삭제 + AddToQueue: 큐 추가 AreYouSureDeleteJob: 이 작업을 삭제하시겠습니까? AreYouSureDeleteQueue: 이 %{queue} 큐를 삭제하시겠습니까? Queues: 큐 diff --git a/web/locales/nl.yml b/web/locales/nl.yml index 454ec54a..6b558c8b 100644 --- a/web/locales/nl.yml +++ b/web/locales/nl.yml @@ -25,6 +25,7 @@ nl: ShowAll: Toon alle CurrentMessagesInQueue: Aantal berichten in %{queue} Delete: Verwijderen + AddToQueue: Toevoegen aan wachtrij AreYouSureDeleteJob: Weet u zeker dat u deze taak wilt verwijderen? AreYouSureDeleteQueue: Weet u zeker dat u wachtrij %{queue} wilt verwijderen? Queues: Wachtrijen diff --git a/web/locales/no.yml b/web/locales/no.yml index cfc686b7..5fa618a3 100644 --- a/web/locales/no.yml +++ b/web/locales/no.yml @@ -25,6 +25,7 @@ no: ShowAll: Vis alle CurrentMessagesInQueue: Nåværende melding i %{queue} Delete: Slett + AddToQueue: Legg til i kø AreYouSureDeleteJob: Er du sikker på at du vil slette denne jobben? AreYouSureDeleteQueue: Er du sikker på at du vil slette køen %{queue}? Queues: Køer diff --git a/web/locales/pl.yml b/web/locales/pl.yml index bb6de1e8..b0d732ad 100644 --- a/web/locales/pl.yml +++ b/web/locales/pl.yml @@ -24,6 +24,7 @@ pl: ShowAll: Pokaż wszystko CurrentMessagesInQueue: Aktualne wiadomości w kolejce %{queue} Delete: Usuń + AddToQueue: dodaj do kolejki AreYouSureDeleteJob: Czy na pewno usunąć to zadanie? AreYouSureDeleteQueue: Czy na pewno usunąć kolejkę %{queue}? Queues: Kolejki diff --git a/web/locales/pt-br.yml b/web/locales/pt-br.yml index 6a626efd..b4297e8c 100644 --- a/web/locales/pt-br.yml +++ b/web/locales/pt-br.yml @@ -25,6 +25,7 @@ ShowAll: Mostrar todos CurrentMessagesInQueue: Mensagens atualmenta na %{queue} Delete: Apagar + AddToQueue: Adicionar à fila AreYouSureDeleteJob: Deseja deletar esta tarefa? AreYouSureDeleteQueue: Deseja deletar a %{queue} fila? Queues: Filas diff --git a/web/locales/pt.yml b/web/locales/pt.yml index b43476b4..a2d215a4 100644 --- a/web/locales/pt.yml +++ b/web/locales/pt.yml @@ -24,6 +24,7 @@ pt: ShowAll: Mostrar todos CurrentMessagesInQueue: Mensagens na fila %{queue} Delete: Apagar + AddToQueue: Adicionar à fila AreYouSureDeleteJob: Tem a certeza que deseja eliminar esta tarefa? AreYouSureDeleteQueue: Tem a certeza que deseja eliminar a fila %{queue}? Queues: Filas diff --git a/web/locales/ru.yml b/web/locales/ru.yml index 247fdf61..56c9e862 100644 --- a/web/locales/ru.yml +++ b/web/locales/ru.yml @@ -24,6 +24,7 @@ ru: ShowAll: Показать все CurrentMessagesInQueue: Текущие сообщения в %{queue} Delete: Удалить + AddToQueue: Добавить в очередь AreYouSureDeleteJob: Вы уверены в том, что хотите удалить задание? AreYouSureDeleteQueue: Вы уверены в том, что хотите удалить очередь %{queue}? Queues: Очереди diff --git a/web/views/scheduled.slim b/web/views/scheduled.slim index a390c1f4..1108497f 100644 --- a/web/views/scheduled.slim +++ b/web/views/scheduled.slim @@ -26,5 +26,6 @@ header.row td= msg['class'] td= display_args(msg['args']) input.btn.btn-danger.pull-right type="submit" name="delete" value="#{t('Delete')}" + input.btn.btn-danger.pull-right type="submit" name="add_to_queue" value="#{t('AddToQueue')}" - else .alert.alert-success = t('NoScheduledFound') From e169a30929e042e738386dbcd279e3b11edbb969 Mon Sep 17 00:00:00 2001 From: Guilherme Ceolin Date: Sun, 23 Jun 2013 19:57:52 -0300 Subject: [PATCH 2/4] Adding some tests --- test/test_api.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_api.rb b/test/test_api.rb index b72eebec..943b46cb 100644 --- a/test/test_api.rb +++ b/test/test_api.rb @@ -172,6 +172,18 @@ class TestApi < Minitest::Test assert_equal 0, q.size end + it "can move scheduled job to queue" do + job_id = ApiWorker.perform_in(100, 1, 'jason') + job = Sidekiq::ScheduledSet.new.find_job(job_id) + q = Sidekiq::Queue.new + job.add_to_queue + queued_job = q.find_job(job_id) + refute_nil queued_job + assert_equal queued_job.jid, job_id + job = Sidekiq::ScheduledSet.new.find_job(job_id) + assert_nil job + end + it 'can find job by id in sorted sets' do job_id = ApiWorker.perform_in(100, 1, 'jason') job = Sidekiq::ScheduledSet.new.find_job(job_id) From fae67c17d72ad3c2d23ceee4729dd85792017116 Mon Sep 17 00:00:00 2001 From: Guilherme Ceolin Date: Sun, 23 Jun 2013 20:22:54 -0300 Subject: [PATCH 3/4] Web tests --- test/test_web.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_web.rb b/test/test_web.rb index ab54bf3d..fb85d32b 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -178,6 +178,22 @@ class TestWeb < Minitest::Test end end + it "can move scheduled to default queue" do + params = add_scheduled + Sidekiq.redis do |conn| + assert_equal 1, conn.zcard('schedule') + assert_equal 0, conn.zcard('default') + post '/scheduled', 'key' => [job_params(*params)], 'add_to_queue' => 'AddToQueue' + assert_equal 302, last_response.status + assert_equal 'http://example.org/scheduled', last_response.header['Location'] + assert_equal 0, conn.zcard('schedule') + get '/queues/default' + assert_equal 200, last_response.status + assert_match /#{params[0]['args'][2]}/, last_response.body + end + + end + it 'can retry all retries' do msg, score = add_retry add_retry From cba10fdeb6c340d1784a8c58721ee19d262ba30c Mon Sep 17 00:00:00 2001 From: Guilherme Ceolin Date: Sun, 23 Jun 2013 21:06:12 -0300 Subject: [PATCH 4/4] adding #1020 to Changes.md --- Changes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index ee98f666..cf0f7bc2 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,6 @@ HEAD ----------- - +- Adding button to move scheduled job to main queue [guiceolin, #1020] - fix i18n support resetting saved locale when job is retried [#1011] - log rotation via USR2 now closes the old logger [#1008]