singleton-client-test 0.7.0.22 → 0.7.0.26

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: 2082040853f3d440a7b553e29c4df5d224661b4b78eb097a58affbe989975823
4
- data.tar.gz: 4a8571720c12840af891c9e5d9a41da1bdf5593fa13e41ab43ac87416311bff7
3
+ metadata.gz: 6a0d174f65d5ce5b87ead4f4c61bc57070bc051ab51bc65343c7ca50a0fd0b68
4
+ data.tar.gz: eaf356bee612ecf0f512083e029964de5307acd3dc05555c710ce386384346ea
5
5
  SHA512:
6
- metadata.gz: 2ab00997146011e894f21ce5b340abadd24890906f16c7e9731d058ab63f5c6da0a67ac225a1148a73516a9743797002626868ec7daada8441bcb412ad5b591d
7
- data.tar.gz: f0c5225b09ab87fe78cb38abe7505a74b9717873ff00f7119190f829c61644efa4fdfb18a79306c2531277dd9bedc24d26e623ba11ab417a20b2a1787d167e48
6
+ metadata.gz: 512573410bae6caa91cf0b893f27e95a0864a0374e75bd601a55a2f471ca75ed69c6f537aeb24ca7b9202a6bc59c231a838c3d5a167fdc56f130c8ab844a32e5
7
+ data.tar.gz: 6a2f2f82f806b564ede5218c7cda2123e528515f5089bb4ea3658451598174d140006e9d075ed68e4b1ae3c04b78b4dc3892a00bc26e447387edb282a8f35c9b
@@ -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)
@@ -5,10 +5,11 @@ module SgtnClient::Core
5
5
  Entry = Struct.new(:expiry, :value)
6
6
 
7
7
  def self.initialize(disabled=false, opts={})
8
- $opts = opts
8
+ @@opts = opts
9
+ @mutex = Mutex.new
9
10
  SgtnClient.logger.debug "Initialize cache......"
10
11
  if disabled == false
11
- $data = Hash.new
12
+ @@data = Hash.new
12
13
  SgtnClient.logger.debug "Cache is enabled!"
13
14
  else
14
15
  SgtnClient.logger.debug "Cache is disabled!"
@@ -16,67 +17,75 @@ module SgtnClient::Core
16
17
  end
17
18
 
18
19
  def self.keys
19
- if $data == nil
20
+ if @@data == nil
20
21
  return nil
21
22
  end
22
23
  SgtnClient.logger.debug "Get cache keys"
23
- $data.keys
24
+ @@data.keys
24
25
  end
25
26
 
26
27
  def self.get(key)
27
- if $data == nil
28
+ if @@data == nil
28
29
  return nil
29
30
  end
30
31
  SgtnClient.logger.debug "Get cache for key: " + key
31
32
  invalidate
32
- $data[key][:value] if has(key)
33
+ @@data[key][:value] if has(key)
33
34
  end
34
35
 
35
36
  def self.has(key)
36
- if $data == nil
37
+ if @@data == nil
37
38
  return nil
38
39
  end
39
40
  SgtnClient.logger.debug "Has cache for key: " + key
40
- $data.has_key? key
41
+ @@data.has_key? key
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.22
4
+ version: 0.7.0.26
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-09 00:00:00.000000000 Z
11
+ date: 2022-01-25 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