serf_handler 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/serf_handler.rb +18 -1
- data/serf_handler.gemspec +1 -1
- data/spec/serf_handler_spec.rb +39 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d33048b27550b3dca5819f6169b83bae581b64be
|
4
|
+
data.tar.gz: 8b9b281100c01c077e04c3fc8babe5246e91c598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e65bf47996eadf228055a613601549c9fd61a2182f54c1e4e3e39168eef2a07e29b1bbf1d49a8e56fae7338d3100562d65c5d8ef518db9eb02580c444db09d5
|
7
|
+
data.tar.gz: 0682ee1ea57d4839e7fb94f46cb3be42d3cb9fb93071d25ecbca52d2e6018a7bdf1034b355603cbfe9ed603a5e596f09f68abe27e7ab90d18277be058a31a91c
|
data/README.md
CHANGED
@@ -19,13 +19,20 @@ gem install serf_handler
|
|
19
19
|
require 'serf_handler'
|
20
20
|
|
21
21
|
class MyEventHandler < SerfHandler
|
22
|
-
|
22
|
+
def initialize
|
23
|
+
# if logfile not specified, log outputs to STDOUT.
|
24
|
+
super("/path/to/logfile")
|
25
|
+
end
|
26
|
+
|
27
|
+
# called by SerfHandlerProxy when member-join event occurs
|
23
28
|
def member_join
|
29
|
+
log "start processing member-join event"
|
24
30
|
# write your code
|
25
31
|
end
|
26
32
|
|
27
|
-
# called by
|
33
|
+
# called by SerfHandlerProxy when your custome event occurs
|
28
34
|
def your_custome_event
|
35
|
+
log "start processing custom event"
|
29
36
|
# write your code
|
30
37
|
end
|
31
38
|
end
|
@@ -33,6 +40,8 @@ end
|
|
33
40
|
if __FILE__ == $0
|
34
41
|
handler = SerfHandlerProxy.new
|
35
42
|
handler.register('MyRole', MyEventHandler.new)
|
43
|
+
# another code
|
44
|
+
# handler.regiter('default', MyEventHandler.new)
|
36
45
|
handler.run
|
37
46
|
end
|
38
47
|
```
|
data/lib/serf_handler.rb
CHANGED
@@ -19,12 +19,29 @@ class SerfHandler
|
|
19
19
|
end
|
20
20
|
@name = ENV['SERF_SELF_NAME']
|
21
21
|
@role = ENV['SERF_TAG_ROLE'] || ENV['SERF_SELF_ROLE']
|
22
|
-
@event =
|
22
|
+
@event = case ENV['SERF_EVENT']
|
23
|
+
when 'user'
|
24
|
+
ENV['SERF_USER_EVENT']
|
25
|
+
when 'query'
|
26
|
+
ENV['SERF_QUERY_NAME']
|
27
|
+
else
|
28
|
+
ENV['SERF_EVENT'].gsub(/-/, '_')
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
def log(msg)
|
26
33
|
@logger.info(msg)
|
27
34
|
end
|
35
|
+
|
36
|
+
def response(msg)
|
37
|
+
if msg.bytesize > 1024
|
38
|
+
message = "message exceeds limit of 1024 bytes."
|
39
|
+
log message
|
40
|
+
puts message
|
41
|
+
else
|
42
|
+
puts msg
|
43
|
+
end
|
44
|
+
end
|
28
45
|
end
|
29
46
|
|
30
47
|
class SerfHandlerProxy < SerfHandler
|
data/serf_handler.gemspec
CHANGED
data/spec/serf_handler_spec.rb
CHANGED
@@ -65,7 +65,7 @@ describe "SerfHandlerProxy" do
|
|
65
65
|
logger = double('Logger')
|
66
66
|
expect(logger).to receive(:info).with("no handler for role").and_return(true)
|
67
67
|
handler = SerfHandlerProxy.new(logger)
|
68
|
-
handler.run
|
68
|
+
expect(handler.run).to be true
|
69
69
|
end
|
70
70
|
|
71
71
|
it "has no method implemented" do
|
@@ -73,7 +73,7 @@ describe "SerfHandlerProxy" do
|
|
73
73
|
expect(logger).to receive(:info).with("member_join event not implemented by class").and_return(true)
|
74
74
|
handler = SerfHandlerProxy.new(logger)
|
75
75
|
handler.register('default', SerfHandler.new)
|
76
|
-
handler.run
|
76
|
+
expect(handler.run).to be true
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -90,7 +90,41 @@ describe "SerfHandlerProxy" do
|
|
90
90
|
sample = double('SerfHandler')
|
91
91
|
expect(sample).to receive(:implemented).and_return(true)
|
92
92
|
handler.register('default', sample)
|
93
|
-
handler.run
|
93
|
+
expect(handler.run).to be true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "Test custom query" do
|
98
|
+
before do
|
99
|
+
ENV['SERF_SELF_NAME'] = nil
|
100
|
+
ENV['SERF_SELF_ROLE'] = nil
|
101
|
+
ENV['SERF_EVENT'] = 'query'
|
102
|
+
ENV['SERF_QUERY_NAME'] = 'query_command'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "has method to process custom event" do
|
106
|
+
handler = SerfHandlerProxy.new
|
107
|
+
sample = double('SerfHandler')
|
108
|
+
expect(sample).to receive(:query_command).and_return(true)
|
109
|
+
handler.register('default', sample)
|
110
|
+
expect(handler.run).to be true
|
111
|
+
end
|
112
|
+
|
113
|
+
it "exceeds limitation" do
|
114
|
+
handler = SerfHandler.new
|
115
|
+
message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at purus sapien. Fusce vitae odio tristique,
|
116
|
+
lacinia purus sed, dictum risus. Nullam rhoncus auctor sapien, nec interdum diam interdum sed. Nulla quis
|
117
|
+
posuere justo. Donec porta, odio eget mollis laoreet, elit leo sollicitudin nisl, luctus vehicula velit
|
118
|
+
erat eu est. Fusce ligula urna, blandit a iaculis nec, suscipit ut purus. Donec sed magna ac mi cursus
|
119
|
+
faucibus. Maecenas vehicula turpis sit amet lacus cursus, quis ultricies nisi porta. Donec risus ligula,
|
120
|
+
elementum eget est nec, vestibulum aliquet nisi. Sed lacinia adipiscing risus, id vulputate leo posuere in.
|
121
|
+
Duis rutrum varius magna, eget feugiat orci tempor vel. Vestibulum massa lacus, dictum in rutrum tristique,
|
122
|
+
varius ultrices neque. Donec fringilla odio eget elementum dignissim. Aliquam ut lectus neque.
|
123
|
+
Donec nec hendrerit dolor. Phasellus ac augue lobortis, vestibulum lacus at, ornare enim. Donec condimentum
|
124
|
+
quis tellus vulputate auctor. Fusce eu tortor vel velit gravida eleifend id a lorem. Maecenas porta est vel
|
125
|
+
sollicitudin ornare. Morbi et commodo diam, non congue nisi. Pellentesque mattis enim lobortis, hendrerit
|
126
|
+
nulla eget, tempus diam. Donec orci aliquam."
|
127
|
+
expect{ handler.response(message) }.to output("message exceeds limit of 1024 bytes.\n").to_stdout
|
94
128
|
end
|
95
129
|
end
|
96
130
|
|
@@ -105,7 +139,7 @@ describe "SerfHandlerProxy" do
|
|
105
139
|
sample = double('SerfHandler')
|
106
140
|
expect(sample).to receive(:member_join).and_return(true)
|
107
141
|
handler.register('default', sample)
|
108
|
-
handler.run
|
142
|
+
expect(handler.run).to be true
|
109
143
|
end
|
110
144
|
end
|
111
145
|
|
@@ -121,7 +155,7 @@ describe "SerfHandlerProxy" do
|
|
121
155
|
sample = double('SerfHandler')
|
122
156
|
expect(sample).to receive(:member_join).and_return(true)
|
123
157
|
handler.register('web', sample)
|
124
|
-
handler.run
|
158
|
+
expect(handler.run).to be true
|
125
159
|
end
|
126
160
|
end
|
127
161
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serf_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KONNO Katsuyuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|