singleton-client-test 0.7.0.21 → 0.7.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6a32015e94de289514c6587a66bd298bae1cc4a0beb577fe1652a290d6da7d5
4
- data.tar.gz: '048750240bb9fa432ae55cf59de230294554203075d3d1213aee11e0f1fdcc8d'
3
+ metadata.gz: 581b02396037c20da7ab2a9248e8522c60735bd1e6e11dd8d4a15af259737b2c
4
+ data.tar.gz: ec310a666d7c5384e552fdaad105d06972fded90df51f0760a4622abc8e39489
5
5
  SHA512:
6
- metadata.gz: 1ea50e6bb782afda6877e0f2ebc978fbfa1ae4aca97aeec79f667a761536f882a2ba604e807471e802c9be37b2704f71e5bfe33e66dfde4975772cb9fdf9e569
7
- data.tar.gz: d9e63703cbdd8527d7c2ff89016d252c71ae9f56edec8bd15b947d99ff7fda0347e972635a0231b717f66793b7e69bfbf4fde20a72d529a8f1f38d51a5e127d3
6
+ metadata.gz: b51088e04941faff963f289b7bbfefcfa9730f78682cb85adca816044dc1432972c3eb1c1f940ac2128b4953397a2ab565a1dbfc0b63fe00f9d79f49b4de7b3a
7
+ data.tar.gz: 545e8d51467d99c4ea57eb45d9f23a651997de2b07fe9eb331fd39f7042728fe2d23312ff8b0fda0f83564674aaf3d42fcf921266241913e875bb2371ccd1af6
@@ -1,5 +1,3 @@
1
- require 'erb'
2
- require 'yaml'
3
1
 
4
2
  module SgtnClient
5
3
 
@@ -45,9 +43,10 @@ module SgtnClient
45
43
  SgtnClient::Config.configurations.default = locale
46
44
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
47
45
  SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
48
- Dir.children(source_bundle).each do |component|
46
+ Dir.foreach(source_bundle) do |component|
47
+ next if component == '.' || component == '..'
49
48
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
50
- bundle = read_yml(yamlfile)
49
+ bundle = SgtnClient::FileUtil.read_yml(yamlfile)
51
50
  cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale)
52
51
  SgtnClient::CacheUtil.write_cache(cachekey,bundle)
53
52
  end
@@ -60,18 +59,13 @@ module SgtnClient
60
59
  bundlepath = source_bundle + "/" + component + "/" + locale + ".yml"
61
60
  SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
62
61
  begin
63
- bundle = read_yml(bundlepath)
62
+ bundle = SgtnClient::FileUtil.read_yml(bundlepath)
64
63
  rescue => exception
65
64
  SgtnClient.logger.error exception.message
66
65
  end
67
66
  return bundle
68
67
  end
69
68
 
70
- def self.read_yml(file_name)
71
- erb = ERB.new(File.read(file_name))
72
- erb.filename = file_name
73
- YAML.load(erb.result)
74
- end
75
69
  end
76
70
 
77
71
  end
@@ -73,7 +73,12 @@ module SgtnClient
73
73
  items = SgtnClient::CacheUtil.get_cache(cache_key)
74
74
  if items.nil?
75
75
  items = getTranslations(component, flocale)
76
- SgtnClient::CacheUtil.write_cache(cache_key, items)
76
+ if items.nil?
77
+ items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
78
+ SgtnClient::Core::Cache.put(cache_key, items, 60)
79
+ else
80
+ SgtnClient::CacheUtil.write_cache(cache_key, items)
81
+ end
77
82
  else
78
83
  SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
79
84
  end
@@ -101,13 +106,7 @@ module SgtnClient
101
106
  translation_bundle = SgtnClient::Config.configurations[env]["translation_bundle"]
102
107
  bundlepath = translation_bundle + "/" + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
103
108
  SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
104
- begin
105
- file = File.read(bundlepath)
106
- data_hash = MultiJson.load(file)
107
- rescue => exception
108
- SgtnClient.logger.error exception.message
109
- end
110
- return data_hash
109
+ SgtnClient::FileUtil.read_json(bundlepath)
111
110
  end
112
111
 
113
112
  def self.get_server(component, locale)
@@ -6,6 +6,7 @@ module SgtnClient::Core
6
6
 
7
7
  def self.initialize(disabled=false, opts={})
8
8
  $opts = opts
9
+ @mutex = Mutex.new
9
10
  SgtnClient.logger.debug "Initialize cache......"
10
11
  if disabled == false
11
12
  $data = Hash.new
@@ -41,42 +42,50 @@ module SgtnClient::Core
41
42
  end
42
43
 
43
44
  def self.put(key, value, ttl=nil)
44
- if $data == nil
45
- return nil
45
+ @mutex.synchronize do
46
+ if $data == nil
47
+ return nil
48
+ end
49
+ ttl ||= @opts[:ttl]
50
+ # hours from new
51
+ SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
52
+ $data[key] = Entry.new(Time.now + ttl*60, value)
46
53
  end
47
- ttl ||= @opts[:ttl]
48
- # hours from new
49
- SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
50
- $data[key] = Entry.new(Time.now + ttl*60, value)
51
54
  end
52
55
 
53
56
  def self.delete(key)
54
- if $data == nil
55
- return nil
57
+ @mutex.synchronize do
58
+ if $data == nil
59
+ return nil
60
+ end
61
+ SgtnClient.logger.debug "Delete cache for key: " + key
62
+ $data.delete key
56
63
  end
57
- SgtnClient.logger.debug "Delete cache for key: " + key
58
- $data.delete key
59
64
  end
60
65
 
61
66
  def self.clear
62
- if $data == nil
63
- return nil
67
+ @mutex.synchronize do
68
+ if $data == nil
69
+ return nil
70
+ end
71
+ SgtnClient.logger.debug "Clear cache!"
72
+ $data = Hash.new
64
73
  end
65
- SgtnClient.logger.debug "Clear cache!"
66
- $data = Hash.new
67
74
  end
68
75
 
69
76
  def self.invalidate
70
- if $data == nil
71
- return nil
77
+ @mutex.synchronize do
78
+ if $data == nil
79
+ return nil
80
+ end
81
+ SgtnClient.logger.debug "Invalidating expired cache......"
82
+ now = Time.now
83
+ $data.each {
84
+ |k, v|
85
+ SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
86
+ }
87
+ $data.delete_if {|k, v| v[:expiry] < now}
72
88
  end
73
- SgtnClient.logger.debug "Invalidating expired cache......"
74
- now = Time.now
75
- $data.each {
76
- |k, v|
77
- SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
78
- }
79
- $data.delete_if {|k, v| v[:expiry] < now}
80
89
  end
81
90
  end
82
91
 
@@ -4,7 +4,11 @@ require 'multi_json'
4
4
  module SgtnClient::Core
5
5
  class Request
6
6
  def self.get(url)
7
- res = RestClient.get(url)
7
+ #res = RestClient.get(url)
8
+ res = RestClient::Resource.new(
9
+ url,
10
+ :verify_ssl => false
11
+ ).get
8
12
  begin
9
13
  obj = MultiJson.load(res)
10
14
  rescue MultiJson::ParseError => exception
@@ -11,6 +11,7 @@ module SgtnClient
11
11
  autoload :Exceptions, "sgtn-client/core/exceptions"
12
12
  autoload :ValidateUtil, "sgtn-client/util/validate-util"
13
13
  autoload :LocaleUtil, "sgtn-client/util/locale-util"
14
+ autoload :FileUtil, "sgtn-client/util/file-util"
14
15
 
15
16
  module Formatters
16
17
  autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
@@ -0,0 +1,32 @@
1
+ require 'erb'
2
+ require 'yaml'
3
+
4
+ module SgtnClient
5
+
6
+ class FileUtil
7
+
8
+ @mutex = Mutex.new
9
+
10
+ def self.read_json(bundlepath)
11
+ @mutex.synchronize do
12
+ data_hash = nil
13
+ begin
14
+ file = File.read(bundlepath)
15
+ data_hash = MultiJson.load(file)
16
+ rescue => exception
17
+ SgtnClient.logger.error exception.message
18
+ end
19
+ return data_hash
20
+ end
21
+ end
22
+
23
+ def self.read_yml(file_name)
24
+ @mutex.synchronize do
25
+ erb = ERB.new(File.read(file_name))
26
+ erb.filename = file_name
27
+ YAML.load(erb.result)
28
+ end
29
+ end
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-client-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.21
4
+ version: 0.7.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware G11n Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-08 00:00:00.000000000 Z
11
+ date: 2022-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -282,6 +282,7 @@ files:
282
282
  - lib/sgtn-client/formatters/plurals/plural_formatter.rb
283
283
  - lib/sgtn-client/sgtn-client.rb
284
284
  - lib/sgtn-client/util/cache-util.rb
285
+ - lib/sgtn-client/util/file-util.rb
285
286
  - lib/sgtn-client/util/locale-util.rb
286
287
  - lib/sgtn-client/util/validate-util.rb
287
288
  - lib/singleton-ruby.rb