Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add delete and retry now operations to web UI

  • Loading branch information...
commit ad73a8ee3acfeac3861216ef980f06f02b2c59bd 1 parent 94d2824
@mperham mperham authored
Showing with 41 additions and 7 deletions.
  1. +10 −0 config.ru
  2. +23 −3 lib/sidekiq/web.rb
  3. +8 −4 web/views/retry.slim
View
10 config.ru
@@ -4,5 +4,15 @@ Sidekiq.configure_client do |config|
config.redis = { :size => 1 }
end
+#Sidekiq.redis {|conn| conn.flushdb }
+#10.times do |idx|
+ #Sidekiq::Client.push('class' => 'HardWorker', 'args' => ['foo', 0.1, idx])
+#end
+
+#Sidekiq.redis { |conn| conn.zadd('retry', Time.now.utc.to_f + 3000, MultiJson.encode({
+ #'class' => 'HardWorker', 'args' => ['foo', 0.1, Time.now.to_f],
+ #'queue' => 'default', 'error_message' => 'No such method', 'error_class' => 'NoMethodError',
+ #'failed_at' => Time.now.utc, 'retry_count' => 0 })) }
+
require 'sidekiq/web'
run Sidekiq::Web
View
26 lib/sidekiq/web.rb
@@ -87,8 +87,8 @@ def queues
def retries_with_score(score)
Sidekiq.redis do |conn|
- results = conn.zrangebyscore('retry', score, score, :withscores => true)
- results.each_slice(2).map { |msg, score| [MultiJson.decode(msg), Float(score)] }
+ results = conn.zrangebyscore('retry', score, score)
+ results.map { |msg| MultiJson.decode(msg) }
end
end
@@ -129,9 +129,29 @@ def relative_time(time)
get "/retries/:score" do
halt 404 unless params[:score]
- @score = params[:score]
+ @score = params[:score].to_f
slim :retry
end
+
+ post "/retries/:score" do
+ halt 404 unless params[:score]
+ score = params[:score].to_f
+ if params['retry']
+ Sidekiq.redis do |conn|
+ results = conn.zrangebyscore('retry', score, score)
+ conn.zremrangebyscore('retry', score, score)
+ results.map do |message|
+ msg = MultiJson.decode(message)
+ conn.rpush("queue:#{msg['queue']}", message)
+ end
+ end
+ elsif params['delete']
+ Sidekiq.redis do |conn|
+ conn.zremrangebyscore('retry', score, score)
+ end
+ end
+ redirect root_path
+ end
end
end
View
12 web/views/retry.slim
@@ -1,13 +1,13 @@
header
- h1 Retry Job #{@score}
+ h1 Retry Job
-- retries_with_score(@score).each do |(msg, score)|
+- retries_with_score(@score).each do |msg|
table class="table table-striped table-bordered"
tbody
tr
th Queue
td
- a href="queues/#{msg['queue']}" #{msg['queue']}
+ a href="#{root_path}queues/#{msg['queue']}" #{msg['queue']}
tr
th Job Class
td
@@ -36,5 +36,9 @@ header
td== relative_time(Time.parse(msg['failed_at']))
tr
th Next Retry
- td== relative_time(Time.at(score))
+ td== relative_time(Time.at(@score))
+ form.form-horizontal action="#{root_path}retries/#{@score}" method="post"
+ a.btn href="#{root_path}" ← Back
+ input.btn.btn-primary type="submit" name="retry" value="Retry Now"
+ input.btn.btn-danger type="submit" name="delete" value="Delete"
Please sign in to comment.
Something went wrong with that request. Please try again.