@@ -6,45 +6,45 @@ class Service::App < Sinatra::Base
6
6
7
7
# Hooks the given Service to a Sinatra route.
8
8
#
9
- # svc - Service class.
9
+ # svc_class - Service class.
10
10
#
11
11
# Returns nothing.
12
- def self . service ( svc )
13
- post "/#{ svc . hook_name } /:event" do
12
+ def self . service ( svc_class )
13
+ post "/#{ svc_class . hook_name } /:event" do
14
14
boom = nil
15
15
time = Time . now . to_f
16
16
data = nil
17
17
begin
18
18
event , data , payload = parse_request
19
- if svc . receive ( event , data , payload )
20
- status 200
21
- ""
19
+ if svc = svc_class . receive ( event , data , payload )
20
+ log_service_request svc , 200
21
+ "OK "
22
22
else
23
- status 404
24
- status "#{ svc . hook_name } Service does not respond to 'push' events"
23
+ log_service_request svc , 200
24
+ "#{ svc_class . hook_name } Service does not respond to 'push' events"
25
25
end
26
26
rescue Faraday ::Error ::ConnectionFailed => boom
27
- status 503
27
+ log_service_request svc , 503
28
28
boom . message
29
29
rescue Service ::ConfigurationError => boom
30
- status 400
30
+ log_service_request svc , 400
31
31
boom . message
32
32
rescue Timeout ::Error , Service ::TimeoutError => boom
33
- status 504
33
+ log_service_request svc , 504
34
34
"Service Timeout"
35
35
rescue Service ::MissingError => boom
36
- status 404
36
+ log_service_request svc , 404
37
37
boom . message
38
38
rescue Object => boom
39
- report_exception svc , data , boom ,
39
+ report_exception svc_class , data , boom ,
40
40
:event => event , :payload => payload . inspect
41
- status 500
41
+ log_service_request svc , 500
42
42
"ERROR"
43
43
ensure
44
44
duration = Time . now . to_f - time
45
- if svc != Service ::Web && duration > 9
45
+ if svc_class != Service ::Web && duration > 9
46
46
boom ||= Service ::TimeoutError . new ( "Long Service Hook" )
47
- report_exception svc , data , boom ,
47
+ report_exception svc_class , data , boom ,
48
48
:event => event , :payload => payload . inspect ,
49
49
:duration => "#{ duration } s"
50
50
end
@@ -77,6 +77,10 @@ def parse_http_request
77
77
[ params [ :event ] , data , payload ]
78
78
end
79
79
80
+ def log_service_request ( svc , code )
81
+ status code
82
+ end
83
+
80
84
# Reports the given exception to Haystack.
81
85
#
82
86
# exception - An Exception instance.
0 commit comments