lib/sidetiq/web.rb in sidetiq-0.3.7 vs lib/sidetiq/web.rb in sidetiq-0.4.0.rc1
- old
+ new
@@ -3,47 +3,67 @@
module Sidetiq
module Web
VIEWS = File.expand_path('views', File.dirname(__FILE__))
def self.registered(app)
- app.helpers do
- def sidetiq_clock
- Sidetiq::Clock.instance
- end
+ app.get "/sidetiq" do
+ @schedules = Sidetiq.schedules
+ @time = Sidetiq.clock.gettime
+ erb File.read(File.join(VIEWS, 'sidetiq.erb'))
+ end
- def sidetiq_schedules
- sidetiq_clock.schedules
- end
+ app.get "/sidetiq/locks" do
+ @locks = Sidetiq::Lock::Redis.all.map(&:meta_data)
+
+ erb File.read(File.join(VIEWS, 'locks.erb'))
end
- app.get "/sidetiq" do
- @schedules = sidetiq_schedules
- @time = sidetiq_clock.gettime
- erb File.read(File.join(VIEWS, 'sidetiq.erb'))
+ app.get "/sidetiq/:name/schedule" do
+ halt 404 unless (name = params[:name])
+
+ @time = Sidetiq.clock.gettime
+
+ @worker, @schedule = Sidetiq.schedules.select do |worker, _|
+ worker.name == name
+ end.flatten
+
+ erb File.read(File.join(VIEWS, 'schedule.erb'))
end
- app.get "/sidetiq/:name" do
+ app.get "/sidetiq/:name/history" do
halt 404 unless (name = params[:name])
- @time = sidetiq_clock.gettime
+ @time = Sidetiq.clock.gettime
- @worker, @schedule = sidetiq_schedules.select do |worker, _|
+ @worker, @schedule = Sidetiq.schedules.select do |worker, _|
worker.name == name
end.flatten
- erb File.read(File.join(VIEWS, 'sidetiq_details.erb'))
+ @history = Sidekiq.redis do |redis|
+ redis.lrange("sidetiq:#{@worker.name}:history", 0, -1)
+ end
+
+ erb File.read(File.join(VIEWS, 'history.erb'))
end
app.post "/sidetiq/:name/trigger" do
halt 404 unless (name = params[:name])
- worker, _ = sidetiq_schedules.select do |w, _|
+ worker, _ = Sidetiq.schedules.select do |w, _|
w.name == name
end.flatten
worker.perform_async
redirect "#{root_path}sidetiq"
+ end
+
+ app.post "/sidetiq/:name/unlock" do
+ halt 404 unless (name = params[:name])
+
+ Sidetiq::Lock::Redis.new(name).unlock!
+
+ redirect "#{root_path}sidetiq/locks"
end
end
end
end