scribe-rb 2.2.rc3 → 2.2.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/README.md +39 -8
- data/lib/extras/facebook_base_handler.rb +23 -10
- data/lib/extras/queued_log_message_handler.rb +23 -0
- data/lib/scribe-rb.rb +1 -0
- data/scribe-rb.gemspec +2 -2
- data/spec/lib/extras/queued_log_message_handler_spec.rb +23 -0
- metadata +21 -16
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -9,14 +9,34 @@ from generic *.thrift files.
|
|
9
9
|
This gem tries to alleviate that slight annoyance and package everything
|
10
10
|
you need to communicate with Scribe.
|
11
11
|
|
12
|
+
It also contains a some "extras" that alleviate a few gotchas I found
|
13
|
+
while creating a Scribe consumer/server.
|
14
|
+
|
12
15
|
## Installation
|
13
16
|
|
14
|
-
|
17
|
+
### Bundler
|
18
|
+
|
19
|
+
Add to `Gemfile` and run `bundle install`:
|
15
20
|
|
16
21
|
```ruby
|
17
22
|
gem 'scribe-rb'
|
18
23
|
```
|
19
24
|
|
25
|
+
### Without Bundler
|
26
|
+
|
27
|
+
Install the gem:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
gem install scribe-rb
|
31
|
+
```
|
32
|
+
|
33
|
+
Require it explicitly in your scripts:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require "rubygems"
|
37
|
+
require "scribe-rb"
|
38
|
+
```
|
39
|
+
|
20
40
|
## Producer (Client)
|
21
41
|
|
22
42
|
```ruby
|
@@ -43,14 +63,23 @@ transport.close
|
|
43
63
|
# Define a handler that inherits from FacebookService::BaseHandler
|
44
64
|
class MyScribeHandler < FacebookService::BaseHandler
|
45
65
|
def Log(messages)
|
46
|
-
#
|
47
|
-
|
48
|
-
|
66
|
+
# Process the array of LogEntry instances passed
|
67
|
+
messages.each do |message|
|
68
|
+
puts "#{message.category}: #{message.message}"
|
69
|
+
end
|
70
|
+
|
71
|
+
# If messages were processed correctly, return `ResultCode::OK`
|
72
|
+
#
|
73
|
+
# To tell the Scribe producer/broker to resend messages later (e.g.,
|
74
|
+
# because this process is under too much load), return
|
75
|
+
# `ResultCode::TRY_LATER`
|
76
|
+
|
77
|
+
# Must return `ResultCode::OK` or `ResultCode::TRY_LATER`
|
49
78
|
ResultCode::OK
|
50
79
|
end
|
51
80
|
end
|
52
81
|
|
53
|
-
#
|
82
|
+
# Setup
|
54
83
|
handler = MyScribeHandler.new("My Scribe Handler")
|
55
84
|
processor = Scribe::Processor.new(handler)
|
56
85
|
|
@@ -59,10 +88,12 @@ transport = Thrift::ServerSocket.new(5678) # 5678 is port number
|
|
59
88
|
transportFactory = Thrift::FramedTransportFactory.new
|
60
89
|
protocolFactory = Thrift::NonStrictBinaryProtocolFactory.new
|
61
90
|
|
62
|
-
#
|
91
|
+
# There are multiple options for server type
|
92
|
+
# * [Thrift::SimpleServer](http://rubydoc.info/gems/thrift/0.7.0/Thrift/SimpleServer): single threaded server (simplest)
|
93
|
+
# * [Thrift::ThreadedServer](http://rubydoc.info/gems/thrift/0.7.0/Thrift/ThreadedServer): server that spawns a thread to handle messages
|
94
|
+
# * [Thrift::ThreadPoolServer](http://rubydoc.info/gems/thrift/0.7.0/Thrift/ThreadPoolServer): server that uses a constant number of threads as workers
|
95
|
+
# * [Thrift::NonblockingServer](http://rubydoc.info/gems/thrift/0.7.0/Thrift/NonblockingServer): server that uses non-blocking I/O
|
63
96
|
server = Thrift::SimpleServer.new(processor, transport, transportFactory, protocolFactory)
|
64
|
-
|
65
|
-
# Blocks thread and runs until process is stopped
|
66
97
|
server.serve
|
67
98
|
```
|
68
99
|
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module FacebookService
|
2
|
-
# TODO: Not thread safe
|
3
2
|
class BaseHandler
|
4
3
|
def initialize(name)
|
5
|
-
@name
|
6
|
-
@alive
|
7
|
-
|
8
|
-
@
|
4
|
+
@name = name
|
5
|
+
@alive = Time.now.to_i
|
6
|
+
|
7
|
+
@counters = Hash.new { |h, k| h[k] = 0 }
|
8
|
+
@counters_mutex = Mutex.new
|
9
|
+
|
10
|
+
@options = Hash.new
|
11
|
+
@options_mutex = Mutex.new
|
9
12
|
end
|
10
13
|
|
11
14
|
def getName
|
@@ -25,23 +28,33 @@ module FacebookService
|
|
25
28
|
end
|
26
29
|
|
27
30
|
def getCounters
|
28
|
-
@
|
31
|
+
@counters_mutex.synchronize do
|
32
|
+
@counters
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def getCounter(key)
|
32
|
-
@
|
37
|
+
@counters_mutex.synchronize do
|
38
|
+
@counters[key]
|
39
|
+
end
|
33
40
|
end
|
34
41
|
|
35
42
|
def setOption(key, value)
|
36
|
-
@
|
43
|
+
@options_mutex.synchronize do
|
44
|
+
@options[key] = value
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
48
|
def getOption(key)
|
40
|
-
@
|
49
|
+
@options_mutex.synchronize do
|
50
|
+
@options[key]
|
51
|
+
end
|
41
52
|
end
|
42
53
|
|
43
54
|
def getOptions
|
44
|
-
@
|
55
|
+
@options_mutex.synchronize do
|
56
|
+
@options
|
57
|
+
end
|
45
58
|
end
|
46
59
|
|
47
60
|
def getCpuProfile(*)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "thread"
|
2
|
+
|
3
|
+
module FacebookService
|
4
|
+
class QueuedLogMessageHandler < BaseHandler
|
5
|
+
attr_reader :queue
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
super(name)
|
9
|
+
|
10
|
+
@queue = Queue.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def Log(messages)
|
14
|
+
messages.each do |message|
|
15
|
+
@queue.push(message)
|
16
|
+
end
|
17
|
+
|
18
|
+
::ResultCode::OK
|
19
|
+
rescue Exception => e
|
20
|
+
::ResultCode::TRY_LATER
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/scribe-rb.rb
CHANGED
@@ -5,3 +5,4 @@ require File.expand_path("generated/scribe", File.dirname(__FILE__))
|
|
5
5
|
|
6
6
|
require File.expand_path("extras/facebook_base_handler", File.dirname(__FILE__))
|
7
7
|
require File.expand_path("extras/non_strict_binary_protocol_factory", File.dirname(__FILE__))
|
8
|
+
require File.expand_path("extras/queued_log_message_handler", File.dirname(__FILE__))
|
data/scribe-rb.gemspec
CHANGED
@@ -3,12 +3,12 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "scribe-rb"
|
6
|
-
s.version = "2.2.
|
6
|
+
s.version = "2.2.rc4"
|
7
7
|
s.authors = ["Andy Lindeman"]
|
8
8
|
s.email = ["andy@highgroove.com"]
|
9
9
|
s.homepage = "http://github.com/highgroove/scribe-rb"
|
10
10
|
s.summary = %q{Generated scribe and fb303 bindings for Ruby packed into a gem}
|
11
|
-
s.description = %q{}
|
11
|
+
s.description = %q{Everything you need to build a Ruby producer/client or consumer/server of Scribe messages}
|
12
12
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FacebookService::QueuedLogMessageHandler do
|
4
|
+
subject do
|
5
|
+
described_class.new("Test Handler")
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#queue" do
|
9
|
+
it "provides access to messages received" do
|
10
|
+
subject.Log(["foo", "bar", "baz"])
|
11
|
+
|
12
|
+
subject.queue.pop.should eq("foo")
|
13
|
+
subject.queue.pop.should eq("bar")
|
14
|
+
subject.queue.pop.should eq("baz")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#log" do
|
19
|
+
it "returns ResultCode::OK" do
|
20
|
+
subject.Log(["foo"]).should eq(ResultCode::OK)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scribe-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.rc4
|
5
5
|
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-09-20 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: thrift
|
17
|
-
requirement: &
|
16
|
+
requirement: &2156662740 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ~>
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: 0.7.0
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156662740
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: rake
|
28
|
-
requirement: &
|
27
|
+
requirement: &2156662140 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156662140
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rspec
|
39
|
-
requirement: &
|
38
|
+
requirement: &2156661320 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ~>
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: 2.6.0
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156661320
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: timecop
|
50
|
-
requirement: &
|
49
|
+
requirement: &2156660580 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
@@ -55,8 +54,9 @@ dependencies:
|
|
55
54
|
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
59
|
-
description:
|
57
|
+
version_requirements: *2156660580
|
58
|
+
description: Everything you need to build a Ruby producer/client or consumer/server
|
59
|
+
of Scribe messages
|
60
60
|
email:
|
61
61
|
- andy@highgroove.com
|
62
62
|
executables: []
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- Rakefile
|
72
72
|
- lib/extras/facebook_base_handler.rb
|
73
73
|
- lib/extras/non_strict_binary_protocol_factory.rb
|
74
|
+
- lib/extras/queued_log_message_handler.rb
|
74
75
|
- lib/generated/facebook_service.rb
|
75
76
|
- lib/generated/fb303_constants.rb
|
76
77
|
- lib/generated/fb303_types.rb
|
@@ -81,8 +82,8 @@ files:
|
|
81
82
|
- scribe-rb.gemspec
|
82
83
|
- spec/lib/extras/facebook_base_handler_spec.rb
|
83
84
|
- spec/lib/extras/non_strict_binary_protocol_factory_spec.rb
|
85
|
+
- spec/lib/extras/queued_log_message_handler_spec.rb
|
84
86
|
- spec/spec_helper.rb
|
85
|
-
has_rdoc: true
|
86
87
|
homepage: http://github.com/highgroove/scribe-rb
|
87
88
|
licenses: []
|
88
89
|
post_install_message:
|
@@ -97,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
segments:
|
99
100
|
- 0
|
100
|
-
hash: -
|
101
|
+
hash: -57725399886143313
|
101
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
103
|
none: false
|
103
104
|
requirements:
|
@@ -106,8 +107,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: 1.3.1
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 1.8.10
|
110
111
|
signing_key:
|
111
112
|
specification_version: 3
|
112
113
|
summary: Generated scribe and fb303 bindings for Ruby packed into a gem
|
113
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- spec/lib/extras/facebook_base_handler_spec.rb
|
116
|
+
- spec/lib/extras/non_strict_binary_protocol_factory_spec.rb
|
117
|
+
- spec/lib/extras/queued_log_message_handler_spec.rb
|
118
|
+
- spec/spec_helper.rb
|