tom 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/dispatcher.rb +6 -6
- data/lib/goliath_api.rb +2 -2
- data/lib/http.rb +4 -2
- data/lib/init.rb +2 -2
- data/lib/tom/log.rb +24 -7
- data/tom.gemspec +2 -2
- metadata +31 -31
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/dispatcher.rb
CHANGED
@@ -13,14 +13,14 @@ module Tom
|
|
13
13
|
def self.dispatch(env)
|
14
14
|
|
15
15
|
# 1. hit APIs. All at the same time. Oh, mygodd!
|
16
|
-
Tom::
|
16
|
+
Tom::Log.logger.info "#{env['REQUEST_METHOD'].upcase} #{env['REQUEST_URI']}"
|
17
17
|
responses = parallel_adapter_dispatch(env)
|
18
18
|
|
19
19
|
# 2. merge
|
20
20
|
merged = merge(env, responses)
|
21
21
|
|
22
22
|
# 3. ???
|
23
|
-
Tom::
|
23
|
+
Tom::Log.logger.info "-------------------------------------------------------"
|
24
24
|
|
25
25
|
# 4. profit
|
26
26
|
merged
|
@@ -40,8 +40,8 @@ module Tom
|
|
40
40
|
def self.merge(env, responses)
|
41
41
|
route, method = route_and_method(env)
|
42
42
|
if merger = Tom::Routes.merger_for_route(route, method)
|
43
|
-
Tom::
|
44
|
-
Tom::
|
43
|
+
Tom::Log.logger.info "Merging with:"
|
44
|
+
Tom::Log.logger.info " -> #{merger}"
|
45
45
|
merged = merger.new.merge(env, responses)
|
46
46
|
else
|
47
47
|
merged = [404, {}, ""]
|
@@ -78,9 +78,9 @@ module Tom
|
|
78
78
|
adapters = Tom::Routes.adapters_for_route(route, method)
|
79
79
|
return responses if adapters.empty?
|
80
80
|
|
81
|
-
Tom::
|
81
|
+
Tom::Log.logger.info "Dispatching to:"
|
82
82
|
EM::Synchrony::FiberIterator.new(adapters, adapters.count).map do |clazz|
|
83
|
-
Tom::
|
83
|
+
Tom::Log.logger.info " -> #{clazz}"
|
84
84
|
(responses[clazz] ||= []) << clazz.new.handle(env)
|
85
85
|
end
|
86
86
|
responses
|
data/lib/goliath_api.rb
CHANGED
@@ -22,8 +22,8 @@ module Tom
|
|
22
22
|
# Hardcoded JSON stacktrace stuff for now...
|
23
23
|
def handle_exception(e, env)
|
24
24
|
trace = e.backtrace.join "\n"
|
25
|
-
Tom::
|
26
|
-
Tom::
|
25
|
+
Tom::Log.logger.info e
|
26
|
+
Tom::Log.logger.info trace
|
27
27
|
[500, {}, {error: e,
|
28
28
|
stacktrace: trace,
|
29
29
|
url: env["REQUEST_URI"]
|
data/lib/http.rb
CHANGED
@@ -12,11 +12,13 @@ module Tom
|
|
12
12
|
# @param options [Hash] Options to pass to EM::HttpRequest's
|
13
13
|
# get/put/post/delete method
|
14
14
|
def self.make_request(method, url, options = {})
|
15
|
-
Tom::
|
15
|
+
Tom::Log.logger.info " curl -X#{method.upcase} -d '#{options[:body]}' #{url}"
|
16
16
|
|
17
17
|
conn = EM::HttpRequest.new(url, connection_options)
|
18
18
|
result = conn.send(method, options)
|
19
|
-
|
19
|
+
|
20
|
+
# Disabling this for a while
|
21
|
+
# handle_errors(method, url, result)
|
20
22
|
|
21
23
|
result
|
22
24
|
end
|
data/lib/init.rb
CHANGED
@@ -7,9 +7,9 @@ Goliath.env rescue Goliath.env = (ENV['RACK_ENV'] || 'development').to_sym
|
|
7
7
|
# In dev mode, we do some logging (defaults to Logger::ERROR in other
|
8
8
|
# envs)
|
9
9
|
if Goliath.env == :development || ENV['BOBS']
|
10
|
-
Tom::
|
10
|
+
Tom::Log.logger.level = Logger::INFO
|
11
11
|
end
|
12
|
-
Tom::
|
12
|
+
Tom::Log.logger.info "Started goliath in #{Goliath.env} environment (change with ruby your_app.rb -e development or by setting $RACK_ENV)"
|
13
13
|
|
14
14
|
# Fetch the codes
|
15
15
|
require_relative 'goliath_api'
|
data/lib/tom/log.rb
CHANGED
@@ -1,11 +1,28 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
3
|
module Tom
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Log
|
5
|
+
|
6
|
+
|
7
|
+
def self.logger=(logger)
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.logger
|
12
|
+
unless @logger
|
13
|
+
@logger = ::Logger.new(STDOUT)
|
14
|
+
init_logger_defaults
|
15
|
+
end
|
16
|
+
@logger
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.init_logger_defaults
|
20
|
+
@logger.level = ::Logger::ERROR
|
21
|
+
@logger.datetime_format = "%H:%M:%S:"
|
22
|
+
Logger::Formatter.module_eval(
|
23
|
+
%q{ def call(severity, time, progname, msg)} +
|
24
|
+
%q{ "#{format_datetime(time)} #{msg2str(msg)}\n" end}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
11
28
|
end
|
data/tom.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tom"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jannis Hermanns"]
|
12
|
-
s.date = "2011-12-
|
12
|
+
s.date = "2011-12-13"
|
13
13
|
s.description = " Tom uses Goliath to dispatch HTTP requests to multiple other APIs (via Adapters) in parallel. In a next step, a Merger merges the result and responds to the clients request."
|
14
14
|
s.email = "jannis@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: goliath
|
16
|
-
requirement: &
|
16
|
+
requirement: &70192164200580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70192164200580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: em-synchrony
|
27
|
-
requirement: &
|
27
|
+
requirement: &70192164200000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70192164200000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: em-http-request
|
38
|
-
requirement: &
|
38
|
+
requirement: &70192164199480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70192164199480
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: json
|
49
|
-
requirement: &
|
49
|
+
requirement: &70192164198920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70192164198920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70192164198340 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.9.2
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70192164198340
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70192164197820 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.0.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70192164197820
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: jeweler
|
82
|
-
requirement: &
|
82
|
+
requirement: &70192164197320 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.6.4
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70192164197320
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: shoulda
|
93
|
-
requirement: &
|
93
|
+
requirement: &70192164196780 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70192164196780
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rcov
|
104
|
-
requirement: &
|
104
|
+
requirement: &70192164196280 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70192164196280
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: ruby-debug19
|
115
|
-
requirement: &
|
115
|
+
requirement: &70192164195780 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70192164195780
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rspec
|
126
|
-
requirement: &
|
126
|
+
requirement: &70192164195280 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70192164195280
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: webmock
|
137
|
-
requirement: &
|
137
|
+
requirement: &70192164194780 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70192164194780
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: yard
|
148
|
-
requirement: &
|
148
|
+
requirement: &70192164194220 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70192164194220
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: rdiscount
|
159
|
-
requirement: &
|
159
|
+
requirement: &70192164193660 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70192164193660
|
168
168
|
description: ! ' Tom uses Goliath to dispatch HTTP requests to multiple other APIs
|
169
169
|
(via Adapters) in parallel. In a next step, a Merger merges the result and responds
|
170
170
|
to the clients request.'
|
@@ -212,7 +212,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
212
212
|
version: '0'
|
213
213
|
segments:
|
214
214
|
- 0
|
215
|
-
hash:
|
215
|
+
hash: 1893692767236117233
|
216
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
217
|
none: false
|
218
218
|
requirements:
|