kronk 1.7.2 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +12 -0
- data/Manifest.txt +1 -1
- data/lib/kronk.rb +3 -3
- data/lib/kronk/cmd.rb +1 -1
- data/lib/kronk/data_string.rb +3 -3
- data/lib/kronk/diff.rb +21 -23
- data/lib/kronk/diff/output.rb +94 -45
- data/lib/kronk/path.rb +7 -0
- data/lib/kronk/path/{path_match.rb → match.rb} +9 -1
- data/lib/kronk/path/matcher.rb +12 -12
- data/lib/kronk/player.rb +2 -2
- data/lib/kronk/player/benchmark.rb +12 -9
- data/lib/kronk/queue_runner.rb +48 -5
- data/test/test_path_match.rb +1 -1
- data/test/test_path_matcher.rb +5 -5
- metadata +3 -3
data/History.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 1.7.3 / 2011-10-25
|
2
|
+
|
3
|
+
* Bugfixes:
|
4
|
+
|
5
|
+
* Handling for parent paths with path matchers.
|
6
|
+
|
7
|
+
* Renamed Path::PathMatch to Path::Match.
|
8
|
+
|
9
|
+
* Fix for benchmark output under ruby 1.8.7.
|
10
|
+
|
11
|
+
* Documentation cleanup.
|
12
|
+
|
1
13
|
=== 1.7.2 / 2011-10-10
|
2
14
|
|
3
15
|
* Bugfixes:
|
data/Manifest.txt
CHANGED
data/lib/kronk.rb
CHANGED
@@ -14,7 +14,7 @@ require 'yaml'
|
|
14
14
|
class Kronk
|
15
15
|
|
16
16
|
# This gem's version.
|
17
|
-
VERSION = '1.7.
|
17
|
+
VERSION = '1.7.3'
|
18
18
|
|
19
19
|
require 'kronk/constants'
|
20
20
|
require 'kronk/queue_runner'
|
@@ -27,7 +27,7 @@ class Kronk
|
|
27
27
|
require 'kronk/player/input_reader'
|
28
28
|
require 'kronk/cmd'
|
29
29
|
require 'kronk/path'
|
30
|
-
require 'kronk/path/
|
30
|
+
require 'kronk/path/match'
|
31
31
|
require 'kronk/path/matcher'
|
32
32
|
require 'kronk/path/transaction'
|
33
33
|
require 'kronk/data_string'
|
@@ -354,7 +354,7 @@ class Kronk
|
|
354
354
|
|
355
355
|
resp
|
356
356
|
|
357
|
-
rescue SocketError,
|
357
|
+
rescue SocketError, SystemCallError
|
358
358
|
raise NotFoundError, "#{uri} could not be found"
|
359
359
|
|
360
360
|
rescue Timeout::Error
|
data/lib/kronk/cmd.rb
CHANGED
@@ -537,7 +537,7 @@ Parse and run diffs against data from live and cached http responses.
|
|
537
537
|
|
538
538
|
exit 1 unless success
|
539
539
|
|
540
|
-
rescue Kronk::Exception,
|
540
|
+
rescue Kronk::Exception, SystemCallError => e
|
541
541
|
error e.message, e.backtrace
|
542
542
|
exit 2
|
543
543
|
end
|
data/lib/kronk/data_string.rb
CHANGED
@@ -15,13 +15,13 @@ class Kronk
|
|
15
15
|
# # }
|
16
16
|
#
|
17
17
|
# dstr.meta[dstr.index("\"a\"")]
|
18
|
-
# #
|
18
|
+
# # []
|
19
19
|
#
|
20
20
|
# dstr.meta[dstr.index("\"foo\"")]
|
21
|
-
# #
|
21
|
+
# # ['a']
|
22
22
|
#
|
23
23
|
# dstr.meta[dstr.index("\"two\"")]
|
24
|
-
# #
|
24
|
+
# # ['c', 1]
|
25
25
|
|
26
26
|
class DataString < String
|
27
27
|
|
data/lib/kronk/diff.rb
CHANGED
@@ -45,7 +45,7 @@ class Kronk
|
|
45
45
|
@diff_ary = nil
|
46
46
|
@char = opts[:char] || /\r?\n/
|
47
47
|
@meta = []
|
48
|
-
@output = Output.new
|
48
|
+
@output = Output.new opts
|
49
49
|
end
|
50
50
|
|
51
51
|
|
@@ -55,10 +55,10 @@ class Kronk
|
|
55
55
|
# str1 = "match1\nin str2\nmore str2\nmatch2\nstr2 val"
|
56
56
|
#
|
57
57
|
# Diff.new(str1, str2).create_diff
|
58
|
-
# ["match 1",
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
58
|
+
# #=> ["match 1",
|
59
|
+
# # [[], ["in str2", "more str2"]],
|
60
|
+
# # "match 2",
|
61
|
+
# # [["str1 val"], ["str2 val"]]]
|
62
62
|
|
63
63
|
def create_diff
|
64
64
|
diff_ary = []
|
@@ -112,7 +112,7 @@ class Kronk
|
|
112
112
|
|
113
113
|
|
114
114
|
##
|
115
|
-
#
|
115
|
+
# Finds non-overlapping common sequences between two arrays and returns
|
116
116
|
# them in the order they occur as an array of arrays:
|
117
117
|
# find_common arr1, arr2
|
118
118
|
# #=> [[size, arr1_index, arr2_index], [size, arr1_index, arr2_index],...]
|
@@ -145,10 +145,12 @@ class Kronk
|
|
145
145
|
|
146
146
|
##
|
147
147
|
# Returns all common sequences between to arrays ordered by sequence length
|
148
|
-
# according to the following format:
|
148
|
+
# (including overlapping ones) according to the following format:
|
149
149
|
# [[[len1, ix, iy], [len1, ix, iy]],[[len2, ix, iy]]]
|
150
150
|
# # e.g.
|
151
151
|
# [nil,[[1,2,3],[1,2,5]],nil,[[3,4,5],[3,6,9]]
|
152
|
+
#
|
153
|
+
# Output is indexed by sequence size.
|
152
154
|
|
153
155
|
def common_sequences arr1, arr2, &block
|
154
156
|
sequences = []
|
@@ -190,22 +192,15 @@ class Kronk
|
|
190
192
|
end
|
191
193
|
|
192
194
|
|
193
|
-
def yield_sequences sequences, dist=0, &block
|
194
|
-
while sequences.length > dist
|
195
|
-
item = sequences.pop
|
196
|
-
next unless item
|
197
|
-
item.each(&block)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
195
|
##
|
203
|
-
# Returns a formatted output as a
|
196
|
+
# Returns a formatted output as a String.
|
204
197
|
|
205
|
-
def formatted
|
206
|
-
@output.render if any?
|
198
|
+
def formatted
|
199
|
+
( @output.render diff_array, @meta if any? ).to_s
|
207
200
|
end
|
208
201
|
|
202
|
+
alias to_s formatted
|
203
|
+
|
209
204
|
|
210
205
|
##
|
211
206
|
# Returns true if any diff is found.
|
@@ -233,11 +228,14 @@ class Kronk
|
|
233
228
|
alias to_a diff_array
|
234
229
|
|
235
230
|
|
236
|
-
|
237
|
-
# Returns a diff string with the default format.
|
231
|
+
private
|
238
232
|
|
239
|
-
def
|
240
|
-
|
233
|
+
def yield_sequences sequences, dist=0, &block # :nodoc:
|
234
|
+
while sequences.length > dist
|
235
|
+
item = sequences.pop
|
236
|
+
next unless item
|
237
|
+
item.each(&block)
|
238
|
+
end
|
241
239
|
end
|
242
240
|
end
|
243
241
|
end
|
data/lib/kronk/diff/output.rb
CHANGED
@@ -13,6 +13,10 @@ class Kronk::Diff
|
|
13
13
|
attr_accessor :context, :format, :lindex, :rindex, :llen, :rlen,
|
14
14
|
:lmeta, :rmeta
|
15
15
|
|
16
|
+
##
|
17
|
+
# Create a new Section to render, with a formatter, lines column
|
18
|
+
# width, and start indexes for left and right side.
|
19
|
+
|
16
20
|
def initialize format, line_num_width=nil, lindex=0, rindex=0
|
17
21
|
@format = format
|
18
22
|
@cwidth = line_num_width
|
@@ -27,6 +31,13 @@ class Kronk::Diff
|
|
27
31
|
end
|
28
32
|
|
29
33
|
|
34
|
+
##
|
35
|
+
# Append a line or diff section to the section.
|
36
|
+
# If obj is a String, common section is assumed, if obj is an Array,
|
37
|
+
# a diff section is assumed.
|
38
|
+
#
|
39
|
+
# Metadata is optional but must be an Array of 2 items if given.
|
40
|
+
|
30
41
|
def add obj, meta=nil
|
31
42
|
@lmeta, @rmeta = meta if meta && !@lmeta && !@rmeta
|
32
43
|
@lmeta = ary_to_path @lmeta if Array === @rmeta
|
@@ -43,7 +54,37 @@ class Kronk::Diff
|
|
43
54
|
end
|
44
55
|
|
45
56
|
|
46
|
-
|
57
|
+
##
|
58
|
+
# Create a Kronk::Path String from an Array. Used when the meta data
|
59
|
+
# given for either side of the diff is an Array.
|
60
|
+
|
61
|
+
def ary_to_path ary
|
62
|
+
"#{Kronk::Path::DCH}#{Kronk::Path.join ary}"
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
##
|
67
|
+
# Build the section String output once all lines and meta has been
|
68
|
+
# added.
|
69
|
+
|
70
|
+
def render
|
71
|
+
cleft = "#{@lindex+1},#{@llen}"
|
72
|
+
cright = "#{@rindex+1},#{@rlen}"
|
73
|
+
|
74
|
+
if @lmeta != @rmeta && @lmeta && @rmeta
|
75
|
+
cleft << " " << @lmeta
|
76
|
+
cright << " " << @rmeta
|
77
|
+
else
|
78
|
+
info = @lmeta || @rmeta
|
79
|
+
end
|
80
|
+
|
81
|
+
[@format.context(cleft, cright, info), *@lines]
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def add_common obj # :nodoc:
|
47
88
|
@llen += 1
|
48
89
|
@rlen += 1
|
49
90
|
@context += 1
|
@@ -55,7 +96,7 @@ class Kronk::Diff
|
|
55
96
|
end
|
56
97
|
|
57
98
|
|
58
|
-
def add_left obj
|
99
|
+
def add_left obj # :nodoc:
|
59
100
|
@llen += 1
|
60
101
|
@context = 0
|
61
102
|
|
@@ -64,33 +105,13 @@ class Kronk::Diff
|
|
64
105
|
end
|
65
106
|
|
66
107
|
|
67
|
-
def add_right obj
|
108
|
+
def add_right obj # :nodoc:
|
68
109
|
@rlen += 1
|
69
110
|
@context = 0
|
70
111
|
|
71
112
|
line_nums = @format.lines [nil, @rlen+@rindex], @cwidth if @cwidth
|
72
113
|
@lines << "#{line_nums}#{@format.added obj}"
|
73
114
|
end
|
74
|
-
|
75
|
-
|
76
|
-
def ary_to_path ary
|
77
|
-
"#{Kronk::Path::DCH}#{Kronk::Path.join ary}"
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
def render
|
82
|
-
cleft = "#{@lindex+1},#{@llen}"
|
83
|
-
cright = "#{@rindex+1},#{@rlen}"
|
84
|
-
|
85
|
-
if @lmeta != @rmeta && @lmeta && @rmeta
|
86
|
-
cleft << " " << @lmeta
|
87
|
-
cright << " " << @rmeta
|
88
|
-
else
|
89
|
-
info = @lmeta || @rmeta
|
90
|
-
end
|
91
|
-
|
92
|
-
[@format.context(cleft, cright, info), *@lines]
|
93
|
-
end
|
94
115
|
end
|
95
116
|
|
96
117
|
|
@@ -122,9 +143,7 @@ class Kronk::Diff
|
|
122
143
|
# :labels:: Array - Left and right names to display; default %w{left right}
|
123
144
|
# :show_lines:: Boolean - Show lines in diff; default false
|
124
145
|
|
125
|
-
def initialize
|
126
|
-
@diff = diff
|
127
|
-
|
146
|
+
def initialize opts={}
|
128
147
|
@format =
|
129
148
|
self.class.formatter(opts[:format] || Kronk.config[:diff_format]) ||
|
130
149
|
AsciiFormat
|
@@ -140,46 +159,78 @@ class Kronk::Diff
|
|
140
159
|
|
141
160
|
@show_lines = opts[:show_lines] || Kronk.config[:show_lines]
|
142
161
|
@section = false
|
143
|
-
|
144
|
-
lines1 = diff.str1.lines.count
|
145
|
-
lines2 = diff.str2.lines.count
|
146
|
-
@cwidth = (lines1 > lines2 ? lines1 : lines2).to_s.length
|
147
162
|
end
|
148
163
|
|
149
164
|
|
150
|
-
|
165
|
+
##
|
166
|
+
# Determine if index i is a part of a section to render, including
|
167
|
+
# surrounding context.
|
168
|
+
|
169
|
+
def section? i, diff_ary
|
151
170
|
!@context ||
|
152
|
-
|
171
|
+
!!diff_ary[i,@context+1].to_a.find{|da| Array === da}
|
153
172
|
end
|
154
173
|
|
155
174
|
|
156
|
-
|
157
|
-
|
175
|
+
##
|
176
|
+
# Determine if index i is the beginning of a diff section to render,
|
177
|
+
# including surrounding context.
|
178
|
+
|
179
|
+
def start_section? i, diff_ary
|
180
|
+
!@section && section?(i, diff_ary)
|
158
181
|
end
|
159
182
|
|
160
183
|
|
161
|
-
|
184
|
+
##
|
185
|
+
# Determine if index i is the end of a diff section to render, including
|
186
|
+
# surrounding context.
|
187
|
+
|
188
|
+
def end_section? i, diff_ary
|
162
189
|
@section &&
|
163
|
-
(i >=
|
164
|
-
!
|
190
|
+
(i >= diff_ary.length ||
|
191
|
+
!section?(i, diff_ary) && @context && @section.context >= @context)
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
##
|
196
|
+
# Determine the width of the line number column from a diff Array.
|
197
|
+
|
198
|
+
def line_col_width diff_ary
|
199
|
+
lines1, lines2 = diff_ary.inject([0,0]) do |prev, obj|
|
200
|
+
if Array === obj
|
201
|
+
[prev[0] + obj[0].length, prev[1] + obj[1].length]
|
202
|
+
else
|
203
|
+
[prev[0] + 1, prev[1] + 1]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
(lines1 > lines2 ? lines1 : lines2).to_s.length
|
165
208
|
end
|
166
209
|
|
167
210
|
|
168
|
-
|
211
|
+
##
|
212
|
+
# Render a diff String from a diff Array, with optional metadata.
|
213
|
+
#
|
214
|
+
# The meta argument must be an Array of 2 Arrays, one for each side of
|
215
|
+
# the diff.
|
216
|
+
|
217
|
+
def render diff_ary, meta=[]
|
169
218
|
output = []
|
170
219
|
output << @format.head(*@labels)
|
171
220
|
|
172
221
|
line1 = line2 = 0
|
173
|
-
lwidth =
|
222
|
+
lwidth = line_col_width diff_ary if @show_lines
|
174
223
|
|
175
|
-
|
176
|
-
@section = Section.new @format, lwidth, line1, line2 if
|
177
|
-
|
224
|
+
diff_ary.each_with_index do |item, i|
|
225
|
+
@section = Section.new @format, lwidth, line1, line2 if
|
226
|
+
start_section? i, diff_ary
|
227
|
+
|
228
|
+
@section.add item, meta[i] if @section
|
178
229
|
|
179
230
|
line1 += Array === item ? item[0].length : 1
|
180
231
|
line2 += Array === item ? item[1].length : 1
|
181
232
|
|
182
|
-
if end_section?(i+1)
|
233
|
+
if end_section?(i+1, diff_ary)
|
183
234
|
output.concat @section.render
|
184
235
|
@section = false
|
185
236
|
end
|
@@ -187,7 +238,5 @@ class Kronk::Diff
|
|
187
238
|
|
188
239
|
output.join(@join_ch)
|
189
240
|
end
|
190
|
-
|
191
|
-
alias to_s render
|
192
241
|
end
|
193
242
|
end
|
data/lib/kronk/path.rb
CHANGED
@@ -122,6 +122,13 @@ class Kronk
|
|
122
122
|
##
|
123
123
|
# Returns a path-keyed data hash. Be careful of mixed key types in hashes
|
124
124
|
# as Symbols and Strings both use #to_s.
|
125
|
+
#
|
126
|
+
# Path.pathed {'foo' => %w{thing bar}, 'fizz' => {'buzz' => 123}}
|
127
|
+
# #=> {
|
128
|
+
# # '/foo/0' => 'thing',
|
129
|
+
# # '/foo/1' => 'bar',
|
130
|
+
# # '/fizz/buzz' => 123
|
131
|
+
# # }
|
125
132
|
|
126
133
|
def self.pathed data, escape=true
|
127
134
|
new_data = {}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
2
|
# Represents the single match of a relative path against a data set.
|
3
3
|
|
4
|
-
class Kronk::Path::
|
4
|
+
class Kronk::Path::Match < Array
|
5
5
|
|
6
6
|
attr_accessor :matches, :splat
|
7
7
|
|
@@ -12,6 +12,14 @@ class Kronk::Path::PathMatch < Array
|
|
12
12
|
end
|
13
13
|
|
14
14
|
|
15
|
+
def [] *args
|
16
|
+
path_match = super
|
17
|
+
path_match.matches = @matches.dup
|
18
|
+
path_match.splat = @splat.map{|key, sp| [key, sp.dup]}
|
19
|
+
path_match
|
20
|
+
end
|
21
|
+
|
22
|
+
|
15
23
|
def append_splat id, key # :nodoc:
|
16
24
|
if @splat[-1] && @splat[-1][0] == id
|
17
25
|
@splat[-1][1] << key
|
data/lib/kronk/path/matcher.rb
CHANGED
@@ -31,6 +31,14 @@ class Kronk::Path::Matcher
|
|
31
31
|
|
32
32
|
|
33
33
|
attr_reader :key, :value, :regex_opts
|
34
|
+
attr_accessor :recursive
|
35
|
+
|
36
|
+
##
|
37
|
+
# New instance of Matcher. Options supported:
|
38
|
+
# :key:: String - The path item key to match.
|
39
|
+
# :value:: String - The path item value to match.
|
40
|
+
# :recursive:: Boolean - Look for path item recursively.
|
41
|
+
# :regex_opts:: Fixnum - representing the Regexp options.
|
34
42
|
|
35
43
|
def initialize opts={}
|
36
44
|
@regex_opts = opts[:regex_opts]
|
@@ -57,7 +65,7 @@ class Kronk::Path::Matcher
|
|
57
65
|
##
|
58
66
|
# Universal iterator for Hash and Array like objects.
|
59
67
|
# The data argument must either respond to both :each_with_index
|
60
|
-
# and :length, or respond to :each yielding a key/value pair.
|
68
|
+
# and :length, or respond to :has_key? and :each yielding a key/value pair.
|
61
69
|
|
62
70
|
def each_data_item data, &block
|
63
71
|
if data.respond_to?(:has_key?) && data.respond_to?(:each)
|
@@ -74,7 +82,7 @@ class Kronk::Path::Matcher
|
|
74
82
|
|
75
83
|
|
76
84
|
##
|
77
|
-
# Finds data with the given key and value matcher, optionally
|
85
|
+
# Finds data with the given key and value matcher, optionally recursive.
|
78
86
|
# Yields data, key and path Array when block is given.
|
79
87
|
# Returns an Array of path arrays.
|
80
88
|
|
@@ -82,8 +90,8 @@ class Kronk::Path::Matcher
|
|
82
90
|
return [] unless Array === data || Hash === data
|
83
91
|
|
84
92
|
paths = []
|
85
|
-
path ||= Kronk::Path::
|
86
|
-
path = Kronk::Path::
|
93
|
+
path ||= Kronk::Path::Match.new
|
94
|
+
path = Kronk::Path::Match.new path if path.class == Array
|
87
95
|
|
88
96
|
each_data_item data do |key, value|
|
89
97
|
c_path = path.dup << key
|
@@ -182,12 +190,4 @@ class Kronk::Path::Matcher
|
|
182
190
|
str
|
183
191
|
end
|
184
192
|
end
|
185
|
-
|
186
|
-
|
187
|
-
##
|
188
|
-
# Should this matcher try and find a match recursively.
|
189
|
-
|
190
|
-
def recursive?
|
191
|
-
@recursive
|
192
|
-
end
|
193
193
|
end
|
data/lib/kronk/player.rb
CHANGED
@@ -8,7 +8,7 @@ class Kronk
|
|
8
8
|
|
9
9
|
class Player < QueueRunner
|
10
10
|
|
11
|
-
RESCUABLE = [Kronk::Exception,
|
11
|
+
RESCUABLE = [Kronk::Exception, SystemCallError, URI::InvalidURIError]
|
12
12
|
|
13
13
|
attr_accessor :input, :output
|
14
14
|
|
@@ -172,7 +172,7 @@ class Kronk
|
|
172
172
|
|
173
173
|
|
174
174
|
##
|
175
|
-
# Check if
|
175
|
+
# Check if we're only processing a single case.
|
176
176
|
# If so, yield a single item and return immediately.
|
177
177
|
|
178
178
|
def single_request?
|
@@ -53,7 +53,7 @@ class Kronk
|
|
53
53
|
@slowest = time if !@slowest || @slowest < time
|
54
54
|
@fastest = time if !@fastest || @fastest > time
|
55
55
|
|
56
|
-
|
56
|
+
log_req resp.request, time if resp.request
|
57
57
|
|
58
58
|
@total_bytes += resp.raw.bytes.count
|
59
59
|
|
@@ -63,13 +63,16 @@ class Kronk
|
|
63
63
|
end
|
64
64
|
|
65
65
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@paths[
|
72
|
-
@paths[
|
66
|
+
def log_req req, time
|
67
|
+
uri = req.uri.dup
|
68
|
+
uri.query = nil
|
69
|
+
uri = "#{req.http_method} #{uri.to_s}"
|
70
|
+
|
71
|
+
@paths[uri] ||= [0, 0]
|
72
|
+
pcount = @paths[uri][1] + 1
|
73
|
+
@paths[uri][0] = (@paths[uri][0] * @paths[uri][1] + time) / pcount
|
74
|
+
@paths[uri][0] = @paths[uri][0].round @precision
|
75
|
+
@paths[uri][1] = pcount
|
73
76
|
end
|
74
77
|
|
75
78
|
|
@@ -173,7 +176,7 @@ Request Percentages (ms)
|
|
173
176
|
unless slowest_reqs.empty?
|
174
177
|
out << "
|
175
178
|
Avg. Slowest Requests (ms, #)
|
176
|
-
#{slowest_reqs.map{|arr| " #{arr[1]} #{arr[0]}"}.join "\n" }"
|
179
|
+
#{slowest_reqs.map{|arr| " #{arr[1].inspect} #{arr[0]}"}.join "\n" }"
|
177
180
|
end
|
178
181
|
|
179
182
|
out
|
data/lib/kronk/queue_runner.rb
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
class Kronk
|
2
2
|
|
3
|
+
##
|
4
|
+
# A basic queue and input processor that supports both a multi-threaded and
|
5
|
+
# evented backend (using EventMachine).
|
6
|
+
#
|
7
|
+
# Input is optional and specified by creating an input trigger
|
8
|
+
# (passing a block to on(:input)).
|
9
|
+
# Input will be used to fill queue as the queue gets depleted by
|
10
|
+
# being processed.
|
11
|
+
#
|
12
|
+
# qrunner = QueueRunner.new
|
13
|
+
# qrunner.concurrency = 20 # thread count
|
14
|
+
# qrunner.number = 100 # process 100 queue items
|
15
|
+
#
|
16
|
+
# file = File.open "example.log", "r"
|
17
|
+
#
|
18
|
+
# qrunner.on :input do
|
19
|
+
# if file.eof?
|
20
|
+
# qrunner.finish
|
21
|
+
# else
|
22
|
+
# file.readline
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# qrunner.on :complete do
|
27
|
+
# file.close
|
28
|
+
# puts "DONE!"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # If running in multi-threaded mode, item mutex will also be passed
|
32
|
+
# # as optional second argument.
|
33
|
+
# qrunner.run do |queue_item|
|
34
|
+
# # Do something with item.
|
35
|
+
# # When running in evented mode, make sure this section is non-blocking.
|
36
|
+
# end
|
37
|
+
|
3
38
|
class QueueRunner
|
4
39
|
|
5
40
|
##
|
@@ -57,6 +92,17 @@ class Kronk
|
|
57
92
|
end
|
58
93
|
|
59
94
|
|
95
|
+
##
|
96
|
+
# Stop runner processing gracefully.
|
97
|
+
|
98
|
+
def finish
|
99
|
+
stop_input!
|
100
|
+
EM.stop if defined?(EM) && EM.reactor_running?
|
101
|
+
@threads.each{|t| t.join}
|
102
|
+
@threads.clear
|
103
|
+
end
|
104
|
+
|
105
|
+
|
60
106
|
##
|
61
107
|
# Immediately end all runner processing and threads.
|
62
108
|
|
@@ -106,10 +152,7 @@ class Kronk
|
|
106
152
|
@count += 1
|
107
153
|
end
|
108
154
|
|
109
|
-
|
110
|
-
@threads.clear
|
111
|
-
|
112
|
-
stop_input!
|
155
|
+
finish
|
113
156
|
end
|
114
157
|
|
115
158
|
|
@@ -136,7 +179,7 @@ class Kronk
|
|
136
179
|
EM.add_periodic_timer do
|
137
180
|
if finished?
|
138
181
|
next if EM.connection_count > 0
|
139
|
-
|
182
|
+
finish
|
140
183
|
next
|
141
184
|
end
|
142
185
|
|
data/test/test_path_match.rb
CHANGED
data/test/test_path_matcher.rb
CHANGED
@@ -30,7 +30,7 @@ class TestPathMatcher < Test::Unit::TestCase
|
|
30
30
|
def test_new
|
31
31
|
assert_equal %r{\Afoo(.*)\Z}, @matcher.key
|
32
32
|
assert_equal %r{\A(.*)bar(.*)\Z}, @matcher.value
|
33
|
-
assert !@matcher.recursive
|
33
|
+
assert !@matcher.recursive
|
34
34
|
end
|
35
35
|
|
36
36
|
|
@@ -158,7 +158,7 @@ class TestPathMatcher < Test::Unit::TestCase
|
|
158
158
|
:recursive => true
|
159
159
|
paths = matcher.find_in @data
|
160
160
|
assert_equal [[:key1, :key1a, 3, :findme]], paths
|
161
|
-
assert_equal Kronk::Path::
|
161
|
+
assert_equal Kronk::Path::Match, paths.first.class
|
162
162
|
|
163
163
|
assert_equal ["me", "in"], paths.first.matches
|
164
164
|
end
|
@@ -176,7 +176,7 @@ class TestPathMatcher < Test::Unit::TestCase
|
|
176
176
|
]
|
177
177
|
|
178
178
|
assert_equal expected_paths, (expected_paths | paths)
|
179
|
-
assert_equal Kronk::Path::
|
179
|
+
assert_equal Kronk::Path::Match, paths.first.class
|
180
180
|
|
181
181
|
assert_equal ["findme"], paths.first.matches
|
182
182
|
end
|
@@ -188,7 +188,7 @@ class TestPathMatcher < Test::Unit::TestCase
|
|
188
188
|
:recursive => true
|
189
189
|
paths = matcher.find_in @data
|
190
190
|
assert_equal [[:key1, :key1a, 3, :findme]], paths
|
191
|
-
assert_equal Kronk::Path::
|
191
|
+
assert_equal Kronk::Path::Match, paths.first.class
|
192
192
|
|
193
193
|
assert_equal ["findme", "in"], paths.first.matches
|
194
194
|
end
|
@@ -211,7 +211,7 @@ class TestPathMatcher < Test::Unit::TestCase
|
|
211
211
|
end
|
212
212
|
|
213
213
|
assert_equal expected_paths, (expected_paths | paths)
|
214
|
-
assert_equal Kronk::Path::
|
214
|
+
assert_equal Kronk::Path::Match, paths.first.class
|
215
215
|
assert_equal expected_paths, (expected_paths | paths.map{|p| p.matches})
|
216
216
|
end
|
217
217
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kronk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.7.
|
5
|
+
version: 1.7.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremie Castagna
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-25 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -125,7 +125,7 @@ files:
|
|
125
125
|
- lib/kronk/diff/output.rb
|
126
126
|
- lib/kronk/path.rb
|
127
127
|
- lib/kronk/path/matcher.rb
|
128
|
-
- lib/kronk/path/
|
128
|
+
- lib/kronk/path/match.rb
|
129
129
|
- lib/kronk/path/transaction.rb
|
130
130
|
- lib/kronk/player.rb
|
131
131
|
- lib/kronk/player/benchmark.rb
|