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: 205d428df157042d2c719d3fc16675987bf5af75
4
- data.tar.gz: 4ed393be15ecd6795e97f49e8157b7e22f105306
3
+ metadata.gz: fe8031fcf2dc7a9c9ccc1943a6a7eef302d15648
4
+ data.tar.gz: 20d9f72bd23ce85b9231bc1ccddb4f10b4771a72
5
5
  SHA512:
6
- metadata.gz: 5f71b85e162c5826caebe3a66a005ded7b60d072c545f5dcbe4363a1257be7ecea1d01ce7282e1599bd15ce488c8a9a75deb9172262447707b66438bccf39221
7
- data.tar.gz: 8f44020c85bcf9bce0d212beeb3682ea4d3f5c9d5f5651086ef4e4191eac3c7872eca778a287d233d4b3b97e8199cab55c86d6c0a4f1a5ba769c3e3a3ec63091
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
- connection.post do |req|
18
- req.url '/api/v1/translations'
19
- req.headers['Content-Type'] = 'application/json'
20
- req.headers['Authorization'] = api_token
21
- req.body = data.to_json
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
- @connection ||= Faraday.new(:url => TranslationEngine.api_host) do |faraday|
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 = TranslationEngine.timeout
75
+ faraday.options.timeout = timeout
68
76
  faraday.options.open_timeout = TranslationEngine.timeout * 4
69
77
  end
70
78
  end
@@ -1,3 +1,3 @@
1
1
  module TranslationEngine
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
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-09-09 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails