-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ru
More file actions
32 lines (25 loc) · 758 Bytes
/
Copy pathconfig.ru
File metadata and controls
32 lines (25 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'bundler'
Bundler.require
require 'lib/stocks'
class App < Sinatra::Base
post '/stockify' do
response.headers["Transfer-Encoding"] = "chunked"
async = env['java.servlet_request'].start_async
text = request.body.read.to_s
settings.thread_pool.post do
begin
puts "Thread(async): #{Thread.current.object_id}"
stocks = Stocks.parse_for_stocks(text)
quotes = Stocks.get_quotes(stocks)
new_text = Stocks.sub_quotes(text, quotes)
async.response.output_stream.println(new_text)
ensure
async.complete
end
end
puts "Thread(main) : #{Thread.current.object_id}"
end
end
App.set :thread_pool,
Concurrent::ThreadPoolExecutor.new(max_threads: 100)
run App