translation_engine 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe8031fcf2dc7a9c9ccc1943a6a7eef302d15648
|
4
|
+
data.tar.gz: 20d9f72bd23ce85b9231bc1ccddb4f10b4771a72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a396afc09a799a4cf485d6cf53b972aa334220aae56bb9bd5d3a588b10edb0ed6bcd6b9df5bb98b85373dfca019b98858b41cbb4495596cc1f9819064ecae5
|
7
|
+
data.tar.gz: 2637aefa8b0c515bfd28cc0e6d5d7474d0036f9c1298c69f0d2359c32734d7f89ed4a2006c58a4359c150b13cac9e102733c2e9d9fab15141c04b23b8c54f90b
|
@@ -8,7 +8,7 @@ class TranslationEngine::ConnectionExceptionMiddleware < Faraday::Middleware
|
|
8
8
|
message = "Connecting to TranslationServer got #{e.class}: #{e.message}"
|
9
9
|
|
10
10
|
if TranslationEngine.raise_exceptions
|
11
|
-
raise ConnectionError, message
|
11
|
+
raise TranslationEngine::ConnectionError, message
|
12
12
|
else
|
13
13
|
Rails.logger.error { message }
|
14
14
|
{}
|
@@ -14,11 +14,19 @@ class TranslationEngine::Connection
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def send_translations(data)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
Thread.new do
|
18
|
+
begin
|
19
|
+
puts "Sending translations in separate thread"
|
20
|
+
connection(60).post do |req|
|
21
|
+
req.url '/api/v1/translations'
|
22
|
+
req.headers['Content-Type'] = 'application/json'
|
23
|
+
req.headers['Authorization'] = api_token
|
24
|
+
req.body = data.to_json
|
25
|
+
end
|
26
|
+
puts "Sending translations in separate thread finished"
|
27
|
+
rescue StandardError => e
|
28
|
+
puts "Sending translations failed: #{e.class}: #{e.message}"
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
@@ -60,11 +68,11 @@ class TranslationEngine::Connection
|
|
60
68
|
|
61
69
|
private
|
62
70
|
|
63
|
-
def connection
|
64
|
-
|
71
|
+
def connection(timeout = TranslationEngine.timeout)
|
72
|
+
Thread.current[:translation_server_connection] ||= Faraday.new(:url => TranslationEngine.api_host) do |faraday|
|
65
73
|
faraday.use TranslationEngine::ConnectionExceptionMiddleware
|
66
74
|
faraday.adapter Faraday.default_adapter
|
67
|
-
faraday.options.timeout =
|
75
|
+
faraday.options.timeout = timeout
|
68
76
|
faraday.options.open_timeout = TranslationEngine.timeout * 4
|
69
77
|
end
|
70
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translation_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondrej Bartas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|