fluq 0.7.1 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 240ecd9e84a3fea2591a68753d3d19ac51cd3d16
4
+ data.tar.gz: e7bf2c74811db0f04aa038005bb20e740184c627
5
+ SHA512:
6
+ metadata.gz: 32e440e6093f7561aa8eb24934657fdaa3b7d20d63e9683e313af0e2b845f8e6eba3a26d980c9e8a34ca98f80fbedc56e17d899651db79376ca704dff54b8fa6
7
+ data.tar.gz: f719ef726e7712087ee14316086e1bc1a350c6f2b9369548ae86e5f35c7c4f629cc03f249a2e48b716ad036fb3a7c4c6b405e2d61930ff106d9f60e967d2dd57
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluq (0.7.1)
4
+ fluq (0.7.3)
5
5
  eventmachine-le
6
6
  msgpack (~> 0.5.0)
7
7
  oj (>= 2.0.10)
@@ -11,20 +11,20 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  diff-lcs (1.2.4)
14
- eventmachine-le (1.1.5)
15
- msgpack (0.5.5)
16
- oj (2.1.3)
14
+ eventmachine-le (1.1.6)
15
+ msgpack (0.5.6)
16
+ oj (2.1.7)
17
17
  rake (10.1.0)
18
- rspec (2.13.0)
19
- rspec-core (~> 2.13.0)
20
- rspec-expectations (~> 2.13.0)
21
- rspec-mocks (~> 2.13.0)
22
- rspec-core (2.13.1)
23
- rspec-expectations (2.13.0)
18
+ rspec (2.14.1)
19
+ rspec-core (~> 2.14.0)
20
+ rspec-expectations (~> 2.14.0)
21
+ rspec-mocks (~> 2.14.0)
22
+ rspec-core (2.14.6)
23
+ rspec-expectations (2.14.3)
24
24
  diff-lcs (>= 1.1.3, < 2.0)
25
- rspec-mocks (2.13.1)
25
+ rspec-mocks (2.14.4)
26
26
  timed_lru (0.3.1)
27
- yard (0.8.6.2)
27
+ yard (0.8.7.2)
28
28
 
29
29
  PLATFORMS
30
30
  java
@@ -8,6 +8,7 @@ require 'eventmachine'
8
8
  require 'msgpack'
9
9
  require 'oj'
10
10
  require 'timed_lru'
11
+ require 'timeout'
11
12
 
12
13
  module FluQ
13
14
  %w'version error mixins'.each do |name|
@@ -1,4 +1,4 @@
1
- class FluQ::DSL::Options
1
+ class FluQ::DSL::Options < ::BasicObject
2
2
 
3
3
  # Constructor
4
4
  # @yield options assigment
@@ -18,7 +18,7 @@ class FluQ::DSL::Options
18
18
  value = args[0]
19
19
  if value && block
20
20
  @opts[name.to_sym] = value
21
- @opts[:"#{name}_options"] = self.class.new(&block).to_hash
21
+ @opts[:"#{name}_options"] = ::FluQ::DSL::Options.new(&block).to_hash
22
22
  else
23
23
  @opts[name.to_sym] = value || block || true
24
24
  end
@@ -44,7 +44,7 @@ class FluQ::Handler::Base
44
44
  # @param [Array<FluQ::Event>] events
45
45
  # @return [Array<FluQ::Event>] matching events
46
46
  def select(events)
47
- events.select &method(:match?)
47
+ events.select {|e| match?(e) }
48
48
  end
49
49
 
50
50
  # @abstract callback, called on each event
@@ -56,7 +56,7 @@ class FluQ::Handler::Base
56
56
 
57
57
  # Configuration defaults
58
58
  def defaults
59
- { pattern: /./ }
59
+ { pattern: /./, timeout: 60 }
60
60
  end
61
61
 
62
62
  # @return [String] generated name
@@ -23,4 +23,4 @@ module FluQ::Mixins::Logger
23
23
  end
24
24
  end
25
25
 
26
- end
26
+ end
@@ -65,8 +65,12 @@ class FluQ::Reactor
65
65
  matching = handler.select(events)
66
66
  next if matching.empty?
67
67
 
68
- handler.on_events(matching)
68
+ ::Timeout.timeout handler.config[:timeout] do
69
+ handler.on_events(matching)
70
+ end
69
71
  logger.info { "#{handler.name} processed #{matching.size}/#{events.size} events in #{((Time.now - start) * 1000).round}ms" }
72
+ rescue Timeout::Error => tx
73
+ logger.crash "#{handler.class.name} #{handler.name} timeout out after #{handler.config[:timeout]}s", tx
70
74
  rescue => ex
71
75
  logger.crash "#{handler.class.name} #{handler.name} failed: #{ex.class.name} #{ex.message}", ex
72
76
  end
@@ -2,6 +2,7 @@ require 'fluq'
2
2
 
3
3
  module FluQ::Testing
4
4
  extend self
5
+ EXCEPTION_TRACKER = ->ex { FluQ::Testing.exceptions.push(ex) }
5
6
 
6
7
  def wait_until(opts = {}, &block)
7
8
  tick = opts[:tick] || 0.01
@@ -9,6 +10,16 @@ module FluQ::Testing
9
10
  Timeout.timeout(max) { sleep(tick) until block.call }
10
11
  rescue Timeout::Error
11
12
  end
13
+
14
+ def exceptions
15
+ @exceptions ||= []
16
+ end
17
+
18
+ def track_exceptions!(logger = FluQ.logger)
19
+ return if logger.exception_handlers.include?(EXCEPTION_TRACKER)
20
+ logger.exception_handler(&EXCEPTION_TRACKER)
21
+ end
22
+
12
23
  end
13
24
 
14
25
  class FluQ::Handler::Test < FluQ::Handler::Base
@@ -23,4 +34,6 @@ class FluQ::Handler::Test < FluQ::Handler::Base
23
34
  raise RuntimeError, "Test Failure!" if events.any? {|e| e.tag == "error.event" }
24
35
  @events.concat events
25
36
  end
37
+
26
38
  end
39
+
@@ -1,3 +1,3 @@
1
1
  module FluQ
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -7,6 +7,11 @@ describe FluQ::DSL::Options do
7
7
  subject.to_hash.should == { val: 42 }
8
8
  end
9
9
 
10
+ it 'should not collide with globals' do
11
+ subject = described_class.new { timeout 43 }
12
+ subject.to_hash.should == { timeout: 43 }
13
+ end
14
+
10
15
  it 'should store block options' do
11
16
  subject = described_class.new { val { 42 } }
12
17
  subject.to_hash[:val].().should == 42
@@ -7,7 +7,7 @@ describe FluQ::Handler::Base do
7
7
  it { should respond_to(:on_events) }
8
8
  it { should be_a(FluQ::Mixins::Loggable) }
9
9
  its(:reactor) { should be(reactor) }
10
- its(:config) { should == { pattern: /./ } }
10
+ its(:config) { should == { pattern: /./, timeout: 60 } }
11
11
  its(:pattern) { should == /./ }
12
12
  its(:name) { should == "base-AxPGxv" }
13
13
 
@@ -67,4 +67,4 @@ describe FluQ::Handler::Base do
67
67
  ]
68
68
  end
69
69
 
70
- end
70
+ end
@@ -10,7 +10,7 @@ describe FluQ::Handler::Log do
10
10
  before { FileUtils.rm_rf(root); FileUtils.mkdir_p(root) }
11
11
 
12
12
  it { should be_a(FluQ::Handler::Base) }
13
- its("config.keys") { should =~ [:convert, :path, :pattern, :rewrite, :cache_max, :cache_ttl] }
13
+ its("config.keys") { should =~ [:convert, :path, :pattern, :rewrite, :cache_max, :cache_ttl, :timeout] }
14
14
 
15
15
  it "can log events" do
16
16
  subject.on_events [event]
@@ -4,6 +4,7 @@ describe FluQ::Reactor do
4
4
 
5
5
  its(:handlers) { should == [] }
6
6
  its(:inputs) { should == [] }
7
+ before { FluQ::Testing.exceptions.clear }
7
8
 
8
9
  def events(*tags)
9
10
  tags.map do |tag|
@@ -53,6 +54,16 @@ describe FluQ::Reactor do
53
54
  subject.process(events("error.event"))
54
55
  10.times { subject.process(events("ok.now")) }
55
56
  h1.should have(20).events
57
+ FluQ::Testing.should have(1).exceptions
58
+ FluQ::Testing.exceptions.last.should be_instance_of(RuntimeError)
56
59
  end
57
60
 
58
- end
61
+ it "should recover timeouts" do
62
+ h1 = subject.register(FluQ::Handler::Test, timeout: 0.001)
63
+ h1.events.should_receive(:concat).and_return {|*| sleep(0.01) }
64
+ subject.process [FluQ::Event.new("ok.event", Time.now.to_i, "sleep" => 0.05)]
65
+ FluQ::Testing.should have(1).exceptions
66
+ FluQ::Testing.exceptions.last.should be_instance_of(Timeout::Error)
67
+ end
68
+
69
+ end
@@ -6,6 +6,7 @@ require 'rspec'
6
6
  require 'fluq/testing'
7
7
 
8
8
  FluQ.logger = Logger.new(FluQ.root.join("log", "fluq.log").to_s)
9
+ FluQ::Testing.track_exceptions!
9
10
 
10
11
  $LOAD_PATH.unshift FluQ.root.join('lib')
11
12
  Random.srand(1234)
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
5
- prerelease:
4
+ version: 0.7.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Black Square Media
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-04 00:00:00.000000000 Z
11
+ date: 2013-10-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: msgpack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,113 +27,99 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: eventmachine-le
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: oj
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 2.0.10
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 2.0.10
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: timed_lru
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: bundler
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: yard
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  description: The minimalistic stream processor
@@ -215,27 +198,26 @@ files:
215
198
  - spec/spec_helper.rb
216
199
  homepage: https://github.com/bsm/fluq
217
200
  licenses: []
201
+ metadata: {}
218
202
  post_install_message:
219
203
  rdoc_options: []
220
204
  require_paths:
221
205
  - lib
222
206
  required_ruby_version: !ruby/object:Gem::Requirement
223
- none: false
224
207
  requirements:
225
- - - ! '>='
208
+ - - '>='
226
209
  - !ruby/object:Gem::Version
227
210
  version: 1.9.1
228
211
  required_rubygems_version: !ruby/object:Gem::Requirement
229
- none: false
230
212
  requirements:
231
- - - ! '>='
213
+ - - '>='
232
214
  - !ruby/object:Gem::Version
233
215
  version: 1.8.0
234
216
  requirements: []
235
217
  rubyforge_project:
236
- rubygems_version: 1.8.25
218
+ rubygems_version: 2.0.3
237
219
  signing_key:
238
- specification_version: 3
220
+ specification_version: 4
239
221
  summary: FluQ
240
222
  test_files: []
241
223
  has_rdoc: