opener-polarity-tagger 3.2.1 → 3.2.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
  SHA256:
3
- metadata.gz: 4f5521ee603c20f1efe4008895c88409afbe7994fe5eab72a1de08766ac36da1
4
- data.tar.gz: 0345c08ea80a4b55c0003a02763fa31837d72e6e38f7fcbb2b7c63a720e00712
3
+ metadata.gz: 27bfb633058aa56d6b5d30fd5557dcfa7e00ecee25005d9258fede4a3544ae47
4
+ data.tar.gz: 8c2877d8c288360c77e64f828587ddd0781cde0171237d85c87dc8a435f0cde8
5
5
  SHA512:
6
- metadata.gz: '02932a66b68aeb50c5c7f77f597ca8f6f6dd55d839796c6609a42eed2afd066ef531316abf1b600e48d7f3f4619a8f1de84d28b7c6858b47fbce4223ec08013f'
7
- data.tar.gz: 41a68399fb4631e5aee6f6c2110d2e6da96ee1d96101b4a95548fc9def1f3e0e5e861cdad453dfb78cebf5de2a7d85dea76af7f9462ae86c55619bff7314a5a6
6
+ metadata.gz: 9c9c8b158fe73cae1d095cfad59b774eca29e034d635baf6795dd9bc96c63e19cc0cd63fab12fa3c560df75e4451f1bbabcd2814ac92bcfa5e3002a966b0eb56
7
+ data.tar.gz: aadffb4278642a1b3e04483a486def241f1be6d2adbce911428588f1962a19fc5392903b805bec04411b128a67f8d6ebca37be285c38b4805617f0f3eb125bae
@@ -4,6 +4,8 @@ module Opener
4
4
 
5
5
  include MonitorMixin
6
6
 
7
+ UPDATE_INTERVAL = (ENV['CACHE_EXPIRE_MINS']&.to_i || 5).minutes
8
+
7
9
  def initialize
8
10
  super #MonitorMixin
9
11
 
@@ -14,13 +16,9 @@ module Opener
14
16
 
15
17
  def [] **params
16
18
  synchronize do
17
- if existing = @cache[params]
18
- existing.tap do
19
- Thread.new{ @cache[params] = cache_update existing, **params }
20
- end
21
- else
22
- @cache[params] = cache_update **params
23
- end
19
+ existing = @cache[params]
20
+ break existing if existing and existing.from > UPDATE_INTERVAL.ago
21
+ @cache[params] = cache_update existing, **params
24
22
  end
25
23
  end
26
24
  alias_method :get, :[]
@@ -29,7 +27,11 @@ module Opener
29
27
  from = Time.now
30
28
  lexicons = load_lexicons cache: existing, **params
31
29
 
32
- return existing if existing and lexicons.blank?
30
+ if existing and lexicons.blank?
31
+ existing.from = from
32
+ return existing
33
+ end
34
+
33
35
  Hashie::Mash.new(
34
36
  lexicons: lexicons,
35
37
  from: from,
@@ -47,7 +49,7 @@ module Opener
47
49
  url += "&if_updated_since=#{cache.from.iso8601}" if cache
48
50
  puts "#{lang}: loading lexicons from url #{url}"
49
51
 
50
- lexicons = JSON.parse HTTPClient.new.get(url).body
52
+ lexicons = JSON.parse http.get(url).body
51
53
  lexicons = lexicons['data'].map{ |l| Hashie::Mash.new l }
52
54
  lexicons
53
55
  end
@@ -83,6 +85,16 @@ module Opener
83
85
  lexicons
84
86
  end
85
87
 
88
+ def http
89
+ return @http if @http
90
+
91
+ @http = HTTPClient.new
92
+ @http.send_timeout = 120
93
+ @http.receive_timeout = 120
94
+ @http.connect_timeout = 120
95
+ @http
96
+ end
97
+
86
98
  end
87
99
  end
88
100
  end
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class PolarityTagger
3
3
 
4
- VERSION = '3.2.1'
4
+ VERSION = '3.2.2'
5
5
 
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-polarity-tagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com