resque-history 1.7.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +6 -0
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/resque-history/helpers/helper.rb +24 -0
- data/lib/resque-history/plugins/history.rb +7 -1
- data/lib/resque-history/server/views/history.erb +2 -0
- data/lib/resque-history/server.rb +2 -0
- data/lib/resque-history.rb +1 -0
- data/resque-history.gemspec +4 -2
- data/spec/resque-history/plugins/history_spec.rb +95 -5
- data/spec/resque-history/resque_history_helper_spec.rb +36 -0
- data/spec/resque-web_spec.rb +11 -0
- metadata +4 -2
data/Changelog.md
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.2
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Resque
|
2
|
+
module History
|
3
|
+
module Helper
|
4
|
+
|
5
|
+
def format_execution(seconds)
|
6
|
+
if seconds.nil?
|
7
|
+
""
|
8
|
+
elsif seconds < 60
|
9
|
+
"#{seconds} secs"
|
10
|
+
elsif seconds < 60 * 60
|
11
|
+
"#{(seconds/60).to_i} minutes"
|
12
|
+
elsif seconds < 60 * 60 * 24
|
13
|
+
"#{(((seconds.to_f/60/60)*100).truncate.to_f)/100} hours"
|
14
|
+
elsif seconds < 60 * 60 * 24 * 7
|
15
|
+
"#{(((seconds.to_f/60/60/24)*100).truncate.to_f)/100} days"
|
16
|
+
else
|
17
|
+
"too long"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -9,10 +9,16 @@ module Resque
|
|
9
9
|
@max_history ||= MAX_HISTORY_SIZE
|
10
10
|
end
|
11
11
|
|
12
|
+
def before_perform_hsitory(*args)
|
13
|
+
@start_time = Time.now
|
14
|
+
end
|
15
|
+
|
12
16
|
def after_perform_history(*args)
|
17
|
+
elapsed_seconds = (Time.now - @start_time).to_i
|
13
18
|
Resque.redis.lpush(HISTORY_SET_NAME, {"class"=>"#{self}",
|
14
19
|
"args"=>args,
|
15
|
-
"time"=>Time.now.strftime("%Y-%m-%d %H:%M")
|
20
|
+
"time"=>Time.now.strftime("%Y-%m-%d %H:%M"),
|
21
|
+
"execution"=>elapsed_seconds
|
16
22
|
}.to_json)
|
17
23
|
|
18
24
|
if Resque.redis.llen(HISTORY_SET_NAME) > maximum_history_size
|
@@ -19,6 +19,7 @@
|
|
19
19
|
<th>Job</th>
|
20
20
|
<th>Arguments</th>
|
21
21
|
<th>Time</th>
|
22
|
+
<th>Execution</th>
|
22
23
|
</tr>
|
23
24
|
<% history.each do |history| %>
|
24
25
|
<% j = JSON.parse(history) %>
|
@@ -26,6 +27,7 @@
|
|
26
27
|
<td class='queue'><%= j["class"] %></td>
|
27
28
|
<td class='args'><%= j["args"] %></td>
|
28
29
|
<td class='args'><%= j["time"] %></td>
|
30
|
+
<td class='args'><%= format_execution(j["execution"]) %></td>
|
29
31
|
</tr>
|
30
32
|
<% end %>
|
31
33
|
</table>
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'resque'
|
2
2
|
require 'resque/server'
|
3
|
+
require 'resque-history'
|
3
4
|
|
4
5
|
# Extends Resque Web Based UI.
|
5
6
|
# Structure has been borrowed from ResqueScheduler.
|
6
7
|
module ResqueHistory
|
7
8
|
module Server
|
8
9
|
include Resque::Helpers
|
10
|
+
include Resque::History::Helper
|
9
11
|
|
10
12
|
def self.erb_path(filename)
|
11
13
|
File.join(File.dirname(__FILE__), 'server', 'views', filename)
|
data/lib/resque-history.rb
CHANGED
data/resque-history.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "resque-history"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.8.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Katzmopolitan"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-07"
|
13
13
|
s.description = "Show history of recently executed jobs"
|
14
14
|
s.email = "ilyakatz@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"Rakefile",
|
33
33
|
"VERSION",
|
34
34
|
"lib/resque-history.rb",
|
35
|
+
"lib/resque-history/helpers/helper.rb",
|
35
36
|
"lib/resque-history/plugins/history.rb",
|
36
37
|
"lib/resque-history/server.rb",
|
37
38
|
"lib/resque-history/server/views/history.erb",
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
"resque-history.gemspec",
|
41
42
|
"spec/redis-test.conf",
|
42
43
|
"spec/resque-history/plugins/history_spec.rb",
|
44
|
+
"spec/resque-history/resque_history_helper_spec.rb",
|
43
45
|
"spec/resque-web_spec.rb",
|
44
46
|
"spec/spec_helper.rb",
|
45
47
|
"test/helper.rb",
|
@@ -18,7 +18,6 @@ class MaxHistoryJob
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
21
|
describe Resque::Plugins::History do
|
23
22
|
it "should be compliance with Resqu::Plugin document" do
|
24
23
|
expect { Resque::Plugin.lint(Resque::Plugins::History) }.to_not raise_error
|
@@ -34,7 +33,7 @@ describe Resque::Plugins::History do
|
|
34
33
|
arr = Resque.redis.lrange(Resque::Plugins::History::HISTORY_SET_NAME, 0, -1)
|
35
34
|
|
36
35
|
arr.count.should == 1
|
37
|
-
JSON.parse(arr.first).should == {"class"=>"HistoryJob", "args"=>[12], "time"=>"2000-09-01 12:00"}
|
36
|
+
JSON.parse(arr.first).should == {"class"=>"HistoryJob", "args"=>[12], "time"=>"2000-09-01 12:00", "execution"=>0}
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
@@ -70,9 +69,9 @@ describe Resque::Plugins::History do
|
|
70
69
|
|
71
70
|
arr.count.should == 3
|
72
71
|
arr.should == [
|
73
|
-
{"class"=>"HistoryJob", "args"=>[11], "time"=>"2000-09-01 12:00"},
|
74
|
-
{"class"=>"HistoryJob", "args"=>[12], "time"=>"2000-09-01 12:00"},
|
75
|
-
{"class"=>"HistoryJob", "args"=>[13], "time"=>"2000-09-01 12:00"}
|
72
|
+
{"class"=>"HistoryJob", "args"=>[11], "time"=>"2000-09-01 12:00", "execution"=>0},
|
73
|
+
{"class"=>"HistoryJob", "args"=>[12], "time"=>"2000-09-01 12:00", "execution"=>0},
|
74
|
+
{"class"=>"HistoryJob", "args"=>[13], "time"=>"2000-09-01 12:00", "execution"=>0}
|
76
75
|
].collect(&:to_json)
|
77
76
|
end
|
78
77
|
|
@@ -101,4 +100,95 @@ describe Resque::Plugins::History do
|
|
101
100
|
|
102
101
|
end
|
103
102
|
|
103
|
+
|
104
|
+
describe "record execution time" do
|
105
|
+
|
106
|
+
it "should record execution time" do
|
107
|
+
|
108
|
+
Resque.enqueue(SlowHistoryJob, 10)
|
109
|
+
|
110
|
+
Timecop.freeze(Time.local(2000, 9, 1, 12, 0, 0)) do
|
111
|
+
job = Resque.reserve('test')
|
112
|
+
job.perform
|
113
|
+
end
|
114
|
+
|
115
|
+
arr = Resque.redis.lrange(Resque::Plugins::History::HISTORY_SET_NAME, 0, -1)
|
116
|
+
|
117
|
+
arr.count.should == 1
|
118
|
+
arr.should == [
|
119
|
+
{"class"=>"SlowHistoryJob", "args"=>[10], "time"=>"2000-09-01 12:10", "execution"=>600}
|
120
|
+
].collect(&:to_json)
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not confuse different job times" do
|
125
|
+
|
126
|
+
Resque.enqueue(SlowHistoryJob, 10)
|
127
|
+
Resque.enqueue(SlowHistoryJob, 5)
|
128
|
+
|
129
|
+
Timecop.freeze(Time.local(2000, 9, 1, 12, 0, 0)) do
|
130
|
+
job = Resque.reserve('test')
|
131
|
+
job.perform
|
132
|
+
|
133
|
+
job = Resque.reserve('test')
|
134
|
+
job.perform
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
arr = Resque.redis.lrange(Resque::Plugins::History::HISTORY_SET_NAME, 0, -1)
|
139
|
+
|
140
|
+
arr.count.should == 2
|
141
|
+
arr.should == [
|
142
|
+
{"class"=>"SlowHistoryJob", "args"=>[5], "time"=>"2000-09-01 12:15", "execution"=>300},
|
143
|
+
{"class"=>"SlowHistoryJob", "args"=>[10], "time"=>"2000-09-01 12:10", "execution"=>600}
|
144
|
+
].collect(&:to_json)
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should record times in the order of completion not in order of starting" do
|
149
|
+
|
150
|
+
#start the longer job first but it should finish last
|
151
|
+
Resque.enqueue(SleepyHistoryJob, 3)
|
152
|
+
Resque.enqueue(SleepyHistoryJob, 1)
|
153
|
+
|
154
|
+
job = Resque.reserve('test')
|
155
|
+
job.perform
|
156
|
+
|
157
|
+
job = Resque.reserve('test')
|
158
|
+
job.perform
|
159
|
+
|
160
|
+
arr = Resque.redis.lrange(Resque::Plugins::History::HISTORY_SET_NAME, 0, -1)
|
161
|
+
|
162
|
+
|
163
|
+
JSON.parse(arr.first)["class"].should =="SleepyHistoryJob"
|
164
|
+
JSON.parse(arr.first)["args"].should ==[1]
|
165
|
+
JSON.parse(arr.first)["execution"].should ==1
|
166
|
+
|
167
|
+
|
168
|
+
JSON.parse(arr.last)["class"].should =="SleepyHistoryJob"
|
169
|
+
JSON.parse(arr.last)["args"].should ==[3]
|
170
|
+
JSON.parse(arr.last)["execution"].should ==3
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
class SlowHistoryJob
|
179
|
+
extend Resque::Plugins::History
|
180
|
+
@queue = :test
|
181
|
+
|
182
|
+
def self.perform(time_in_minutes)
|
183
|
+
Timecop.travel(Time.now + 60*time_in_minutes)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class SleepyHistoryJob
|
188
|
+
extend Resque::Plugins::History
|
189
|
+
@queue = :test
|
190
|
+
|
191
|
+
def self.perform(time_in_seconds)
|
192
|
+
sleep(time_in_seconds)
|
193
|
+
end
|
104
194
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'resque-history/helpers/helper'
|
3
|
+
|
4
|
+
describe Resque::History::Helper do
|
5
|
+
|
6
|
+
include Resque::History::Helper
|
7
|
+
|
8
|
+
it "should show correct number of seconds" do
|
9
|
+
format_execution(40).should == "40 secs"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should show correct number of minutes" do
|
13
|
+
format_execution(600).should == "10 minutes"
|
14
|
+
format_execution(659).should == "10 minutes"
|
15
|
+
format_execution(660).should == "11 minutes"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should show correct number of hours" do
|
19
|
+
format_execution(3600).should == "1.0 hours"
|
20
|
+
format_execution(7200).should == "2.0 hours"
|
21
|
+
format_execution(5400).should == "1.5 hours"
|
22
|
+
format_execution(5403).should == "1.5 hours"
|
23
|
+
format_execution(5703).should == "1.58 hours"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should show correct number of days" do
|
27
|
+
format_execution(86400).should == "1.0 days"
|
28
|
+
format_execution(129600).should == "1.5 days"
|
29
|
+
format_execution(518400).should == "6.0 days"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should show that job is too long" do
|
33
|
+
format_execution(604800).should == "too long"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/spec/resque-web_spec.rb
CHANGED
@@ -15,6 +15,9 @@ describe ResqueHistory::Server do
|
|
15
15
|
|
16
16
|
before do
|
17
17
|
queues
|
18
|
+
Resque.enqueue(HistoryJob, 12)
|
19
|
+
job = Resque.reserve('test')
|
20
|
+
job.perform
|
18
21
|
end
|
19
22
|
|
20
23
|
it "should respond to /history" do
|
@@ -28,3 +31,11 @@ describe ResqueHistory::Server do
|
|
28
31
|
end
|
29
32
|
|
30
33
|
end
|
34
|
+
|
35
|
+
class HistoryJob
|
36
|
+
extend Resque::Plugins::History
|
37
|
+
@queue = :test
|
38
|
+
|
39
|
+
def self.perform(*args)
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque-history
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- Rakefile
|
147
147
|
- VERSION
|
148
148
|
- lib/resque-history.rb
|
149
|
+
- lib/resque-history/helpers/helper.rb
|
149
150
|
- lib/resque-history/plugins/history.rb
|
150
151
|
- lib/resque-history/server.rb
|
151
152
|
- lib/resque-history/server/views/history.erb
|
@@ -154,6 +155,7 @@ files:
|
|
154
155
|
- resque-history.gemspec
|
155
156
|
- spec/redis-test.conf
|
156
157
|
- spec/resque-history/plugins/history_spec.rb
|
158
|
+
- spec/resque-history/resque_history_helper_spec.rb
|
157
159
|
- spec/resque-web_spec.rb
|
158
160
|
- spec/spec_helper.rb
|
159
161
|
- test/helper.rb
|