diff --git a/lib/sidetiq/config.rb b/lib/sidetiq/config.rb index fa3625b..4b95848 100644 --- a/lib/sidetiq/config.rb +++ b/lib/sidetiq/config.rb @@ -24,7 +24,7 @@ module Sidetiq end configure do |config| - config.worker_history = 100 + config.worker_history = 50 config.resolution = 1 config.lock_expire = 1000 config.utc = false diff --git a/lib/sidetiq/middleware/history.rb b/lib/sidetiq/middleware/history.rb index a1248c4..a3a3e1b 100644 --- a/lib/sidetiq/middleware/history.rb +++ b/lib/sidetiq/middleware/history.rb @@ -32,8 +32,8 @@ module Sidetiq error: "", exception: "", backtrace: "", - processor: "#{Socket.gethostname}:#{Process.pid}-#{Thread.current.object_id}", - processed: Time.now.iso8601 + node: "#{Socket.gethostname}:#{Process.pid}-#{Thread.current.object_id}", + timestamp: Time.now.iso8601 } end diff --git a/lib/sidetiq/views/_worker_nav.erb b/lib/sidetiq/views/_worker_nav.erb new file mode 100644 index 0000000..2429332 --- /dev/null +++ b/lib/sidetiq/views/_worker_nav.erb @@ -0,0 +1,22 @@ +
+ +
diff --git a/lib/sidetiq/views/assets/styles.css b/lib/sidetiq/views/assets/styles.css new file mode 100644 index 0000000..648055a --- /dev/null +++ b/lib/sidetiq/views/assets/styles.css @@ -0,0 +1,36 @@ + + diff --git a/lib/sidetiq/views/sidetiq.erb b/lib/sidetiq/views/sidetiq.erb index 9fd8d92..5b5bda1 100644 --- a/lib/sidetiq/views/sidetiq.erb +++ b/lib/sidetiq/views/sidetiq.erb @@ -15,7 +15,7 @@ <% @schedules.each do |worker, schedule| %> - "><%= worker.name %> + "><%= worker.name %> <%= worker.get_sidekiq_options["queue"] %> <%= relative_time(schedule.next_occurrence(@time)) %> diff --git a/lib/sidetiq/views/sidetiq_details.erb b/lib/sidetiq/views/sidetiq_details.erb deleted file mode 100644 index 55026a8..0000000 --- a/lib/sidetiq/views/sidetiq_details.erb +++ /dev/null @@ -1,49 +0,0 @@ -
-
-

Recurring Job: <%= @worker.name %>

-
-
- -<% if (recurrences = @schedule.recurrence_rules).length > 0 %> - - - - - <% recurrences.each do |rule| %> - - - - <% end %> -
Recurrences
<%= rule.to_s %>
-<% end %> - -
- -<% if (exceptions = @schedule.exception_rules).length > 0 %> - - - - - <% exceptions.each do |rule| %> - - - - <% end %> -
Exceptions
<%= rule.to_s %>
-<% end %> - -
- - - - - - - - - <% end %> -
Next 10 runs - <% @schedule.next_occurrences(10, @time).each do |time| %> -
<%= relative_time(time) %>
- -
diff --git a/lib/sidetiq/views/sidetiq_history.erb b/lib/sidetiq/views/sidetiq_history.erb new file mode 100644 index 0000000..03e331e --- /dev/null +++ b/lib/sidetiq/views/sidetiq_history.erb @@ -0,0 +1,48 @@ +<%= File.read(File.join(File.dirname(__FILE__), 'views', 'assets', 'styles.css')) %> + +
+
+

Recurring Job: <%= @worker.name %>

+
+
+ +
+
+ <%= erb File.read(File.join(File.dirname(__FILE__), 'views', '_worker_nav.erb')) %> + +
+ + + + + + + + <% @history.each do |entry| %> + <% entry = JSON.parse(entry, symbolize_names: true) %> + + + + + + <% end %> +
StatusTimestampDetails
<%= entry[:status].capitalize %><%= Time.parse(entry[:timestamp]).strftime("%m/%d/%Y %I:%M:%S%p") %> + <% if entry[:status] == 'failure' %> + + <%= entry[:exception] %>: <%= entry[:error] %> + +
+
+                <%= entry[:backtrace].join("
") %> +
+
+ <% end %> +

+ Node: <%= entry[:node] %> +

+
+
+
+
+ +
diff --git a/lib/sidetiq/views/sidetiq_history.rb b/lib/sidetiq/views/sidetiq_history.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/sidetiq/views/sidetiq_schedule.erb b/lib/sidetiq/views/sidetiq_schedule.erb new file mode 100644 index 0000000..dbdb34c --- /dev/null +++ b/lib/sidetiq/views/sidetiq_schedule.erb @@ -0,0 +1,59 @@ +<%= File.read(File.join(File.dirname(__FILE__), 'views', 'assets', 'styles.css')) %> + +
+
+

Recurring Job: <%= @worker.name %>

+
+
+ +
+
+ <%= erb File.read(File.join(File.dirname(__FILE__), 'views', '_worker_nav.erb')) %> + +
+ <% if (recurrences = @schedule.recurrence_rules).length > 0 %> + + + + + <% recurrences.each do |rule| %> + + + + <% end %> +
Recurrences
<%= rule.to_s %>
+ <% end %> + +
+ + <% if (exceptions = @schedule.exception_rules).length > 0 %> + + + + + <% exceptions.each do |rule| %> + + + + <% end %> +
Exceptions
<%= rule.to_s %>
+ <% end %> + +
+ + + + + + + + + <% end %> +
Next 10 runs + <% @schedule.next_occurrences(10, @time).each do |time| %> +
<%= relative_time(time) %>
+
+
+
+ +
diff --git a/lib/sidetiq/web.rb b/lib/sidetiq/web.rb index 8d27439..fefda68 100644 --- a/lib/sidetiq/web.rb +++ b/lib/sidetiq/web.rb @@ -11,7 +11,7 @@ module Sidetiq erb File.read(File.join(VIEWS, 'sidetiq.erb')) end - app.get "/sidetiq/:name" do + app.get "/sidetiq/:name/schedule" do halt 404 unless (name = params[:name]) @time = Sidetiq.clock.gettime @@ -20,7 +20,23 @@ module Sidetiq worker.name == name end.flatten - erb File.read(File.join(VIEWS, 'sidetiq_details.erb')) + erb File.read(File.join(VIEWS, 'sidetiq_schedule.erb')) + end + + app.get "/sidetiq/:name/history" do + halt 404 unless (name = params[:name]) + + @time = Sidetiq.clock.gettime + + @worker, @schedule = Sidetiq.schedules.select do |worker, _| + worker.name == name + end.flatten + + @history = Sidekiq.redis do |redis| + redis.lrange("sidetiq:#{@worker.name}:history", 0, -1) + end + + erb File.read(File.join(VIEWS, 'sidetiq_history.erb')) end app.post "/sidetiq/:name/trigger" do diff --git a/test/test_history.rb b/test/test_history.rb index 77d9a10..43bcaef 100644 --- a/test/test_history.rb +++ b/test/test_history.rb @@ -21,8 +21,8 @@ class TestHistory < Sidetiq::TestCase assert_empty actual[:backtrace] assert_empty actual[:exception] - refute_empty actual[:processor] - refute_empty actual[:processed] + refute_empty actual[:node] + refute_empty actual[:timestamp] end def test_failure @@ -45,8 +45,8 @@ class TestHistory < Sidetiq::TestCase assert_equal "StandardError", actual[:exception] refute_empty actual[:backtrace] - refute_empty actual[:processor] - refute_empty actual[:processed] + refute_empty actual[:node] + refute_empty actual[:timestamp] end def middlewared diff --git a/test/test_web.rb b/test/test_web.rb index 9161b44..049440e 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -33,8 +33,13 @@ class TestWeb < Sidetiq::TestCase end end - def test_details_page - get "/sidetiq/ScheduledWorker" + def test_history_page + get "/sidetiq/ScheduledWorker/history" + assert_equal 200, last_response.status + end + + def test_schedule_page + get "/sidetiq/ScheduledWorker/schedule" assert_equal 200, last_response.status schedule = clock.schedules[ScheduledWorker]