File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,21 @@ def ads_for(ip)
8
8
params = { forwardedip : ip }
9
9
params . merge! ( testMode : true , ignore : true ) if Rails . env . development?
10
10
uri = URI ::HTTPS . build ( host : HOST , path : PATH , query : params . to_query )
11
- response = Faraday . get ( uri )
12
- results = JSON . parse ( response . body ) rescue nil
11
+
12
+ results = begin
13
+ start = Time . now
14
+ response = Faraday . new ( url : uri ) . get do |req |
15
+ req . options . timeout = 2 # open/read timeout in seconds
16
+ req . options . open_timeout = 1 # connection open timeout in seconds
17
+ end
18
+ logger . info "sponsor=success seconds=#{ "%.2f" % ( Time . now - start ) } "
19
+
20
+ JSON . parse ( response . body ) rescue nil
21
+ rescue Faraday ::TimeoutError
22
+ logger . info "sponsor=timeout seconds=#{ "%.2f" % ( Time . now - start ) } "
23
+ nil
24
+ end
25
+
13
26
return [ ] if results . nil?
14
27
results [ 'ads' ] . select { |a | a [ 'creativeid' ] } . collect { |data | build_sponsor ( data ) }
15
28
end
Original file line number Diff line number Diff line change 81
81
#
82
82
production :
83
83
<< : *default
84
+ connect_timeout : 1
85
+ checkout_timeout : 1
84
86
database : coderwall-next_production
85
87
username : coderwall-next
86
88
password : <%= ENV['CODERWALL-NEXT_DATABASE_PASSWORD'] %>
89
+ variables :
90
+ statement_timeout : 500 # ms
Original file line number Diff line number Diff line change 2
2
threads_count = Integer ( ENV [ 'MAX_THREADS' ] || 5 )
3
3
threads threads_count , threads_count
4
4
5
+ worker_timeout 15
6
+ worker_shutdown_timeout 8
7
+
5
8
preload_app!
6
9
7
10
rackup DefaultRackup
You can’t perform that action at this time.
0 commit comments