masamune 0.11.7 → 0.11.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/masamune/environment.rb +5 -5
- data/lib/masamune/tasks/elastic_mapreduce_thor.rb +1 -0
- data/lib/masamune/tasks/hive_thor.rb +1 -0
- data/lib/masamune/tasks/postgres_thor.rb +1 -0
- data/lib/masamune/tasks/shell_thor.rb +1 -0
- data/lib/masamune/thor.rb +23 -4
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/environment_spec.rb +1 -1
- data/spec/masamune/thor_spec.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de2a4fd6bb5a2135bcee2683501ac65a90f91ec9
|
4
|
+
data.tar.gz: 9d2ad4ecc076e523b47486a9d03ff4d2089f98f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d4f7a56bb6ad4fbff0f0203474a79285e056e9562a5c13ca29c15932e8698c68c0a741078a6604d4d91bbcbe863cf775fbb01ae75b4f094b11b76145994c107
|
7
|
+
data.tar.gz: abe67971495a36ec39ff4da7ffe8e45185e45574390861640d0d566a8cbffb1f7c9507ddaa402eb7cf87077c08dadff8fb49e2c647bf377ad96c20beacef2ef1
|
data/lib/masamune/environment.rb
CHANGED
@@ -53,28 +53,28 @@ module Masamune
|
|
53
53
|
@mutex ||= Mutex.new
|
54
54
|
end
|
55
55
|
|
56
|
-
def with_exclusive_lock(name
|
56
|
+
def with_exclusive_lock(name)
|
57
57
|
raise 'filesystem path :run_dir not defined' unless filesystem.has_path?(:run_dir)
|
58
58
|
lock_name = [name, configuration.lock].compact.join(':')
|
59
59
|
logger.debug("acquiring lock '#{lock_name}'")
|
60
60
|
lock_file = lock_file(lock_name)
|
61
61
|
lock_mode = File::LOCK_EX
|
62
|
-
lock_mode |= File::LOCK_NB
|
62
|
+
lock_mode |= File::LOCK_NB
|
63
63
|
lock_status = lock_file.flock(lock_mode)
|
64
64
|
if lock_status == 0
|
65
65
|
yield if block_given?
|
66
66
|
else
|
67
|
-
logger.error "acquire lock attempt failed for '#{lock_name}'"
|
67
|
+
logger.error "acquire lock attempt failed for '#{lock_name}'"
|
68
68
|
end
|
69
69
|
ensure
|
70
|
-
if lock_file
|
70
|
+
if lock_file && lock_status == 0
|
71
71
|
logger.debug("releasing lock '#{lock_name}'")
|
72
72
|
lock_file.flock(File::LOCK_UN)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def with_process_lock(name)
|
77
|
-
with_exclusive_lock("#{name}_#{Process.pid}"
|
77
|
+
with_exclusive_lock("#{name}_#{Process.pid}") do
|
78
78
|
yield
|
79
79
|
end
|
80
80
|
end
|
@@ -31,6 +31,7 @@ module Masamune::Tasks
|
|
31
31
|
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
32
32
|
# https://github.com/wycats/thor/pull/247
|
33
33
|
namespace :elastic_mapreduce
|
34
|
+
skip_lock!
|
34
35
|
|
35
36
|
desc 'elastic_mapreduce', 'Launch an ElasticMapReduce ssh session'
|
36
37
|
class_option :template, :type => :string, :aliases => '-t', :desc => 'Execute named template command'
|
@@ -32,6 +32,7 @@ module Masamune::Tasks
|
|
32
32
|
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
33
33
|
# https://github.com/wycats/thor/pull/247
|
34
34
|
namespace :hive
|
35
|
+
skip_lock!
|
35
36
|
|
36
37
|
desc 'hive', 'Launch a Hive session'
|
37
38
|
method_option :file, :aliases => '-f', :desc => 'SQL from files'
|
@@ -31,6 +31,7 @@ module Masamune::Tasks
|
|
31
31
|
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
32
32
|
# https://github.com/wycats/thor/pull/247
|
33
33
|
namespace :postgres
|
34
|
+
skip_lock!
|
34
35
|
|
35
36
|
desc 'psql', 'Launch a Postgres session'
|
36
37
|
method_option :file, :aliases => '-f', :desc => 'SQL from files'
|
@@ -33,6 +33,7 @@ module Masamune::Tasks
|
|
33
33
|
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
34
34
|
# https://github.com/wycats/thor/pull/247
|
35
35
|
namespace :shell
|
36
|
+
skip_lock!
|
36
37
|
|
37
38
|
desc 'shell', 'Launch an interactive shell'
|
38
39
|
method_option :dump, :type => :boolean, :desc => 'Dump SQL schema', :default => false
|
data/lib/masamune/thor.rb
CHANGED
@@ -103,11 +103,11 @@ module Masamune
|
|
103
103
|
class_option :lock, :desc => 'Optional job lock name', :type => :string
|
104
104
|
class_option :initialize, :aliases => '--init', :desc => 'Initialize configured data stores', :type => :boolean, :default => false
|
105
105
|
class_option :'--', :desc => 'Extra pass through arguments'
|
106
|
-
def initialize(_args=[], _options={}, _config={})
|
106
|
+
def initialize(_args = [], _options = {}, _config = {})
|
107
107
|
self.environment.parent = self
|
108
108
|
self.filesystem.environment = self
|
109
109
|
self.current_namespace = self.class.namespace unless self.class.namespace == 'masamune'
|
110
|
-
self.current_task_name = _config[:current_command].name
|
110
|
+
self.current_task_name = _config[:current_command].try(:name)
|
111
111
|
self.current_command_name = current_namespace ? current_namespace + ':' + current_task_name : current_task_name
|
112
112
|
self.class.instance = self
|
113
113
|
|
@@ -162,16 +162,35 @@ module Masamune
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def invoke_command(command, *args)
|
165
|
-
|
165
|
+
return super if self.class.skip_lock?
|
166
|
+
lock_name = qualify_task_name(command.name) + '_command'
|
167
|
+
environment.with_exclusive_lock(lock_name) do
|
166
168
|
super
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
170
172
|
def invoke(name = nil, *args)
|
171
|
-
|
173
|
+
lock_name = qualify_task_name(name) + '_task'
|
174
|
+
environment.with_exclusive_lock(lock_name) do
|
172
175
|
super
|
173
176
|
end
|
174
177
|
end
|
178
|
+
|
179
|
+
def qualify_task_name(task_name)
|
180
|
+
task, namespace = *task_name.split(':').reverse
|
181
|
+
namespace ||= current_namespace
|
182
|
+
"#{namespace}:#{task.gsub(/_task\Z/, '')}"
|
183
|
+
end
|
184
|
+
|
185
|
+
class << self
|
186
|
+
def skip_lock!
|
187
|
+
@skip_lock = true
|
188
|
+
end
|
189
|
+
|
190
|
+
def skip_lock?
|
191
|
+
@skip_lock
|
192
|
+
end
|
193
|
+
end
|
175
194
|
end
|
176
195
|
|
177
196
|
private
|
data/lib/masamune/version.rb
CHANGED
@@ -56,7 +56,7 @@ describe Masamune::Environment do
|
|
56
56
|
before do
|
57
57
|
instance.filesystem.add_path(:run_dir, run_dir)
|
58
58
|
expect(instance.logger).to receive(:error).with(/acquire lock attempt failed for 'some_lock'/)
|
59
|
-
expect_any_instance_of(File).to receive(:flock).
|
59
|
+
expect_any_instance_of(File).to receive(:flock).once.and_return(1)
|
60
60
|
end
|
61
61
|
|
62
62
|
it { expect { |b| instance.with_exclusive_lock('some_lock', &b) }.to_not raise_error }
|
data/spec/masamune/thor_spec.rb
CHANGED
@@ -235,4 +235,37 @@ describe Masamune::Thor do
|
|
235
235
|
it { is_expected.to eq([[], ['--more']]) }
|
236
236
|
end
|
237
237
|
end
|
238
|
+
|
239
|
+
context '#qualify_task_name' do
|
240
|
+
let(:thor_class) do
|
241
|
+
Class.new(Thor) do
|
242
|
+
include Masamune::Thor
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
let(:instance) { thor_class.new([], {}, {}) }
|
247
|
+
|
248
|
+
before do
|
249
|
+
expect(instance).to receive(:current_namespace).at_most(:once).and_return('namespace')
|
250
|
+
end
|
251
|
+
|
252
|
+
subject do
|
253
|
+
instance.qualify_task_name(name)
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'without namespace' do
|
257
|
+
let(:name) { 'other' }
|
258
|
+
it { is_expected.to eq('namespace:other') }
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'with namespace' do
|
262
|
+
let(:name) { 'namespace:other' }
|
263
|
+
it { is_expected.to eq('namespace:other') }
|
264
|
+
end
|
265
|
+
|
266
|
+
context 'with task suffix' do
|
267
|
+
let(:name) { 'namespace:other_task' }
|
268
|
+
it { is_expected.to eq('namespace:other') }
|
269
|
+
end
|
270
|
+
end
|
238
271
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: masamune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Andrews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|