zeta 0.12.3 → 0.12.4

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: f89983d6e8c1a86caa18dd2c70c7232feed564e4
4
- data.tar.gz: 9425b22e845e2072fe48e643992d06a41ecfa451
3
+ metadata.gz: ca59a735f784f683a952d7fe7953f30846ffb918
4
+ data.tar.gz: 79985b345c3e01768d3a57c9b56bcedbf009ad35
5
5
  SHA512:
6
- metadata.gz: b8b6f95426950ccd197785bb59fbc2698f424e85d2f9db831a8a44e9b70d95f6ef0ebe7b66ba30db8702398e9b4a63812289b60227019412575ea7fca8781ef6
7
- data.tar.gz: 6d45ff3c39f792fd99a9b1375aaab85f167e4fad300b45a7c53c3b3eaec23846ac6e8347ae55f78625ba6f5b2c3be87eb395891bb0fc2a1bec0bda9e326117aa
6
+ metadata.gz: 29b5a0005763dc552f3888733482a59713c84998a173c5a7e8a00e605f635d8deb97c92a5c81a4b6d1f47f3393e141c39da3005963fc72f4c9435fd3c83c7bc8
7
+ data.tar.gz: 397479ef539c33bc8308a72b8fe6d6dcfc332e65b239e4974dffc541920362d890882edb1673a535ba29157eac78bb1fde587535b87b8382a1b4f89024296772
@@ -1,3 +1,6 @@
1
+ # 0.12.4
2
+ - More conservative locking
3
+
1
4
  # 0.12.3
2
5
  - Force rspec examples (in RSpec integration of zeta, not its own tests) to run in order
3
6
 
@@ -6,6 +6,24 @@ class Zeta
6
6
  include Zeta::Instance
7
7
  MUTEX = Mutex.new
8
8
 
9
+ def self.instance
10
+ return @instance if @instance
11
+ MUTEX.synchronize do
12
+ unless @instance
13
+ # Create a Zeta instance
14
+ @instance = new(verbose: true)
15
+
16
+ # Copy the current service's specifications to cache dir
17
+ @instance.update_own_contracts
18
+
19
+ # Convert current service's specifications so published and
20
+ # consumed objects of this service can be validated at
21
+ # runtime
22
+ @instance.convert_all!
23
+ end
24
+ end
25
+ end
26
+
9
27
  # Not using the SingleForwardable module here so that, when
10
28
  # somebody tries to figure out how Zeta works by looking at
11
29
  # its methods, they don't get confused.
@@ -13,21 +31,7 @@ class Zeta
13
31
  methods.each do |method|
14
32
  define_singleton_method method do |*args|
15
33
  send_args = [method, args].flatten.compact
16
- MUTEX.synchronize do
17
- unless @singleton
18
- # Create a Zeta singleton
19
- @singleton = new(verbose: true)
20
-
21
- # Copy the current service's specifications to cache dir
22
- @singleton.update_own_contracts
23
-
24
- # Convert current service's specifications so published and
25
- # consumed objects of this service can be validated at
26
- # runtime
27
- @singleton.infrastructure.convert_all!
28
- end
29
- @singleton.send(*send_args)
30
- end
34
+ instance.send(*send_args)
31
35
  end
32
36
  end
33
37
  end
@@ -11,13 +11,13 @@ class Zeta
11
11
  attr_reader :config
12
12
 
13
13
  def initialize(options = {})
14
- @mutex = Mutex.new
14
+ @lock = Monitor.new
15
15
  @options = options
16
16
  end
17
17
 
18
18
  def update_contracts
19
- i = infrastructure
20
- @mutex.synchronize do
19
+ @lock.synchronize do
20
+ i = infrastructure
21
21
  clear_cache
22
22
  puts "Updating #{cache_dir}" if verbose?
23
23
  update_other_contracts
@@ -28,20 +28,21 @@ class Zeta
28
28
  end
29
29
 
30
30
  def convert_all!
31
- i = infrastructure
32
- @mutex.synchronize do
33
- i.convert_all!
31
+ @lock.synchronize do
32
+ infrastructure.convert_all!
34
33
  end
35
34
  end
36
35
 
37
36
  def update_own_contracts
38
- contract_files.each do |file|
39
- source_file = File.join(config[:contracts_path], file)
40
- target_file = File.join(cache_dir, config[:service_name], file)
41
- FileUtils.mkdir_p(File.join(cache_dir, config[:service_name]))
42
- puts "cp #{source_file} #{target_file}" if verbose?
43
- FileUtils.rm_f(target_file)
44
- FileUtils.cp(source_file, target_file) if File.exists?(source_file)
37
+ @lock.synchronize do
38
+ contract_files.each do |file|
39
+ source_file = File.join(config[:contracts_path], file)
40
+ target_file = File.join(cache_dir, config[:service_name], file)
41
+ FileUtils.mkdir_p(File.join(cache_dir, config[:service_name]))
42
+ puts "cp #{source_file} #{target_file}" if verbose?
43
+ FileUtils.rm_f(target_file)
44
+ FileUtils.cp(source_file, target_file) if File.exists?(source_file)
45
+ end
45
46
  end
46
47
  end
47
48
 
@@ -55,7 +56,7 @@ class Zeta
55
56
  end
56
57
 
57
58
  def infrastructure
58
- @mutex.synchronize do
59
+ @lock.synchronize do
59
60
  return @infrastructure if @infrastructure
60
61
  @infrastructure = Lacerda::Infrastructure.new(data_dir: cache_dir, verbose: verbose?)
61
62
  @infrastructure
@@ -79,24 +80,29 @@ class Zeta
79
80
  end
80
81
 
81
82
  def cache_dir
83
+ @lock.synchronize do
82
84
  return @cache_dir if @cache_dir
83
85
  full_path = File.expand_path(config[:contracts_cache_path])
84
86
  FileUtils.mkdir_p(full_path)
85
87
  @cache_dir = full_path
88
+ end
86
89
  end
87
90
 
88
91
  def clear_cache
89
- # I'm afraid of FileUtils.rm_rf so I'll just delete all relevant files
90
- # and then rmdir all empty directories.
91
- Dir[File.join(cache_dir, "**/*.mson")].each{|f| FileUtils.rm(f) }
92
- Dir[File.join(cache_dir, "**/*.json")].each{|f| FileUtils.rm(f) }
93
- Dir[File.join(cache_dir, '*')].each do |d|
94
- next unless File.directory?(d)
95
- FileUtils.rmdir(d) rescue nil
92
+ @lock.synchronize do
93
+ # I'm afraid of FileUtils.rm_rf so I'll just delete all relevant files
94
+ # and then rmdir all empty directories.
95
+ Dir[File.join(cache_dir, "**/*.mson")].each{|f| FileUtils.rm(f) }
96
+ Dir[File.join(cache_dir, "**/*.json")].each{|f| FileUtils.rm(f) }
97
+ Dir[File.join(cache_dir, '*')].each do |d|
98
+ next unless File.directory?(d)
99
+ FileUtils.rmdir(d) rescue nil
100
+ end
96
101
  end
97
102
  end
98
103
 
99
104
  def config
105
+ @lock.synchronize do
100
106
  return @config if @config
101
107
  full_config = YAML.load_file(config_file).with_indifferent_access
102
108
  env_config = full_config[env]
@@ -109,6 +115,7 @@ class Zeta
109
115
  end
110
116
 
111
117
  @config = env_config
118
+ end
112
119
  end
113
120
 
114
121
  def validate_object_to_publish!(type, data)
@@ -1,3 +1,3 @@
1
1
  class Zeta
2
- VERSION = "0.12.3"
2
+ VERSION = "0.12.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 0.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannis Hermanns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.5.1
203
+ rubygems_version: 2.6.6
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Collects and validates the publish/consume contracts of your infrastructure