From 5a25e45bce9ed1c4ea5cb769b7aaf592761a487d Mon Sep 17 00:00:00 2001 From: Andrew Allen Date: Thu, 4 Sep 2014 17:04:04 -0700 Subject: [PATCH 1/2] show runtime of each job on the history page --- lib/sidetiq/middleware/history.rb | 5 ++++- lib/sidetiq/views/history.erb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/sidetiq/middleware/history.rb b/lib/sidetiq/middleware/history.rb index 0119a09..6752096 100644 --- a/lib/sidetiq/middleware/history.rb +++ b/lib/sidetiq/middleware/history.rb @@ -13,6 +13,7 @@ module Sidetiq def call_with_sidetiq_history(worker, msg, queue) entry = new_history_entry + start_time = Time.now yield rescue StandardError => e @@ -23,6 +24,7 @@ module Sidetiq raise e ensure + entry[:runtime] = (Time.now - start_time) save_entry_for_worker(entry, worker) end @@ -33,7 +35,8 @@ module Sidetiq exception: "", backtrace: "", node: "#{Socket.gethostname}:#{Process.pid}-#{Thread.current.object_id}", - timestamp: Time.now.iso8601 + timestamp: Time.now.iso8601, + runtime: "" } end diff --git a/lib/sidetiq/views/history.erb b/lib/sidetiq/views/history.erb index 7531fa8..4e660c1 100644 --- a/lib/sidetiq/views/history.erb +++ b/lib/sidetiq/views/history.erb @@ -17,6 +17,7 @@ Status Timestamp + Runtime Details @@ -25,6 +26,7 @@ <%= entry[:status].capitalize %> <%= Time.parse(entry[:timestamp]).strftime("%m/%d/%Y %I:%M:%S%p") %> + <%= entry[:runtime].round(3) %> s <% if entry[:status] == 'failure' %> From 04bb92a10321708544e0f1732824194c93b6bfe9 Mon Sep 17 00:00:00 2001 From: Andrew Allen Date: Thu, 4 Sep 2014 17:24:28 -0700 Subject: [PATCH 2/2] added tests for runtime --- test/test_history.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_history.rb b/test/test_history.rb index e17b8e7..9dfd201 100644 --- a/test/test_history.rb +++ b/test/test_history.rb @@ -23,6 +23,7 @@ class TestHistory < Sidetiq::TestCase refute_empty actual[:node] refute_empty actual[:timestamp] + assert actual[:runtime] > 0 end def test_failure @@ -47,6 +48,7 @@ class TestHistory < Sidetiq::TestCase refute_empty actual[:node] refute_empty actual[:timestamp] + assert actual[:runtime] > 0 end def middlewared