masamune 0.17.12 → 0.17.13
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 +4 -4
- data/Rakefile +3 -3
- data/bin/masamune-aws-emr +1 -1
- data/bin/masamune-dump +1 -1
- data/bin/masamune-hive +1 -1
- data/bin/masamune-psql +1 -1
- data/bin/masamune-shell +1 -1
- data/lib/masamune.rb +1 -1
- data/lib/masamune/actions/aws_emr.rb +2 -2
- data/lib/masamune/actions/data_flow.rb +10 -10
- data/lib/masamune/actions/date_parse.rb +4 -6
- data/lib/masamune/actions/execute.rb +3 -3
- data/lib/masamune/actions/filesystem.rb +1 -1
- data/lib/masamune/actions/hadoop_filesystem.rb +2 -2
- data/lib/masamune/actions/hive.rb +5 -5
- data/lib/masamune/actions/invoke_parallel.rb +5 -5
- data/lib/masamune/actions/postgres.rb +6 -6
- data/lib/masamune/actions/postgres_admin.rb +1 -1
- data/lib/masamune/actions/s3cmd.rb +3 -3
- data/lib/masamune/actions/transform.rb +4 -4
- data/lib/masamune/after_initialize_callbacks.rb +4 -4
- data/lib/masamune/cached_filesystem.rb +7 -11
- data/lib/masamune/commands/aws_emr.rb +12 -12
- data/lib/masamune/commands/hadoop_filesystem.rb +8 -8
- data/lib/masamune/commands/hadoop_streaming.rb +16 -16
- data/lib/masamune/commands/hive.rb +31 -35
- data/lib/masamune/commands/postgres.rb +30 -32
- data/lib/masamune/commands/postgres_admin.rb +17 -16
- data/lib/masamune/commands/postgres_common.rb +1 -1
- data/lib/masamune/commands/retry_with_backoff.rb +19 -19
- data/lib/masamune/commands/s3cmd.rb +7 -7
- data/lib/masamune/commands/shell.rb +25 -38
- data/lib/masamune/configuration.rb +8 -9
- data/lib/masamune/data_plan/builder.rb +5 -5
- data/lib/masamune/data_plan/elem.rb +7 -7
- data/lib/masamune/data_plan/engine.rb +12 -15
- data/lib/masamune/data_plan/rule.rb +14 -12
- data/lib/masamune/data_plan/set.rb +13 -13
- data/lib/masamune/environment.rb +3 -3
- data/lib/masamune/filesystem.rb +29 -28
- data/lib/masamune/helpers/postgres.rb +8 -5
- data/lib/masamune/io.rb +2 -2
- data/lib/masamune/last_element.rb +3 -3
- data/lib/masamune/method_logger.rb +1 -1
- data/lib/masamune/schema/catalog.rb +9 -12
- data/lib/masamune/schema/column.rb +12 -10
- data/lib/masamune/schema/dimension.rb +5 -4
- data/lib/masamune/schema/fact.rb +2 -2
- data/lib/masamune/schema/map.rb +9 -13
- data/lib/masamune/schema/row.rb +3 -2
- data/lib/masamune/schema/store.rb +13 -14
- data/lib/masamune/schema/table.rb +24 -28
- data/lib/masamune/schema/table_reference.rb +7 -7
- data/lib/masamune/spec_helper.rb +1 -1
- data/lib/masamune/string_format.rb +1 -1
- data/lib/masamune/tasks/aws_emr_thor.rb +9 -9
- data/lib/masamune/tasks/dump_thor.rb +5 -5
- data/lib/masamune/tasks/hive_thor.rb +13 -13
- data/lib/masamune/tasks/postgres_thor.rb +8 -8
- data/lib/masamune/tasks/shell_thor.rb +3 -3
- data/lib/masamune/template.rb +4 -4
- data/lib/masamune/thor.rb +26 -25
- data/lib/masamune/transform/common/denormalize_table.rb +6 -6
- data/lib/masamune/transform/define_table.rb +1 -1
- data/lib/masamune/transform/hive/define_table.rb +0 -2
- data/lib/masamune/transform/insert_reference_values.rb +1 -1
- data/lib/masamune/transform/operator.rb +3 -2
- data/lib/masamune/transform/postgres/bulk_upsert.rb +0 -3
- data/lib/masamune/transform/postgres/deduplicate_dimension.rb +4 -6
- data/lib/masamune/transform/postgres/define_table.rb +2 -2
- data/lib/masamune/transform/postgres/insert_reference_values.rb +1 -4
- data/lib/masamune/transform/postgres/relabel_dimension.rb +1 -3
- data/lib/masamune/transform/postgres/rollup_fact.rb +3 -5
- data/lib/masamune/transform/postgres/snapshot_dimension.rb +1 -4
- data/lib/masamune/transform/postgres/stage_dimension.rb +8 -10
- data/lib/masamune/transform/postgres/stage_fact.rb +15 -14
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/actions/aws_emr_spec.rb +8 -8
- data/spec/masamune/actions/execute_spec.rb +6 -6
- data/spec/masamune/actions/hive_spec.rb +20 -15
- data/spec/masamune/actions/postgres_spec.rb +17 -10
- data/spec/masamune/after_initialization_callbacks_spec.rb +13 -7
- data/spec/masamune/commands/aws_emr_spec.rb +10 -10
- data/spec/masamune/commands/hadoop_filesystem_spec.rb +3 -3
- data/spec/masamune/commands/hadoop_streaming_spec.rb +4 -4
- data/spec/masamune/commands/hive_spec.rb +11 -11
- data/spec/masamune/commands/postgres_admin_spec.rb +9 -9
- data/spec/masamune/commands/postgres_spec.rb +15 -15
- data/spec/masamune/commands/retry_with_backoff_spec.rb +10 -7
- data/spec/masamune/commands/s3cmd_spec.rb +3 -3
- data/spec/masamune/commands/shell_spec.rb +16 -16
- data/spec/masamune/data_plan/builder_spec.rb +22 -19
- data/spec/masamune/data_plan/elem_spec.rb +20 -20
- data/spec/masamune/data_plan/engine_spec.rb +41 -33
- data/spec/masamune/data_plan/rule_spec.rb +19 -19
- data/spec/masamune/data_plan/set_spec.rb +8 -6
- data/spec/masamune/environment_spec.rb +5 -5
- data/spec/masamune/filesystem_spec.rb +87 -87
- data/spec/masamune/helpers/postgres_spec.rb +1 -1
- data/spec/masamune/rspec/job_fixture_spec.rb +0 -1
- data/spec/masamune/schema/catalog_spec.rb +16 -16
- data/spec/masamune/schema/column_spec.rb +19 -19
- data/spec/masamune/schema/dimension_spec.rb +2 -2
- data/spec/masamune/schema/fact_spec.rb +3 -3
- data/spec/masamune/schema/map_spec.rb +41 -41
- data/spec/masamune/schema/table_spec.rb +16 -16
- data/spec/masamune/string_format_spec.rb +7 -7
- data/spec/masamune/tasks/dump_thor_spec.rb +6 -6
- data/spec/masamune/tasks/hive_thor_spec.rb +2 -2
- data/spec/masamune/template_spec.rb +3 -2
- data/spec/masamune/thor_spec.rb +8 -8
- data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +3 -3
- data/spec/masamune/transform/define_table.dimension_spec.rb +3 -3
- data/spec/masamune/transform/define_table.fact_spec.rb +5 -5
- data/spec/masamune/transform/define_table.table_spec.rb +6 -6
- data/spec/masamune/transform/denormalize_table_spec.rb +15 -15
- data/spec/masamune/transform/insert_reference_values.dimension_spec.rb +1 -1
- data/spec/masamune/transform/load_dimension_spec.rb +1 -1
- data/spec/masamune/transform/load_fact_spec.rb +1 -1
- data/spec/masamune/transform/rollup_fact_spec.rb +4 -4
- data/spec/masamune/transform/stage_dimension_spec.rb +3 -3
- data/spec/masamune/transform/stage_fact_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/support/masamune/example_group.rb +2 -2
- data/spec/support/masamune/job_example_group.rb +3 -3
- data/spec/support/masamune/job_fixture.rb +4 -4
- data/spec/support/masamune/mock_command.rb +10 -10
- data/spec/support/masamune/mock_delegate.rb +2 -2
- data/spec/support/masamune/mock_filesystem.rb +3 -3
- data/spec/support/masamune/shared_example_group.rb +14 -16
- data/spec/support/masamune/step_example_group.rb +4 -4
- data/spec/support/masamune/step_fixture.rb +1 -1
- data/spec/support/masamune/task_example_group.rb +1 -1
- data/spec/support/masamune/thor_mute.rb +3 -2
- data/spec/support/rspec/example/action_example_group.rb +1 -1
- data/spec/support/rspec/example/task_example_group.rb +7 -4
- data/spec/support/rspec/example/transform_example_group.rb +1 -1
- data/spec/support/shared_examples/postgres_common_examples.rb +2 -2
- metadata +16 -2
@@ -29,14 +29,14 @@ module Masamune::Commands
|
|
29
29
|
include Masamune::Actions::Execute
|
30
30
|
|
31
31
|
DEFAULT_ATTRIBUTES =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
{
|
33
|
+
path: 'aws',
|
34
|
+
extra: [],
|
35
|
+
config_file: nil,
|
36
|
+
action: nil,
|
37
|
+
cluster_id: nil,
|
38
|
+
interactive: false
|
39
|
+
}.freeze
|
40
40
|
|
41
41
|
def initialize(delegate, attrs = {})
|
42
42
|
super delegate
|
@@ -104,10 +104,10 @@ module Masamune::Commands
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def handle_stdout(line, line_no)
|
107
|
-
if line_no == 0 && line
|
108
|
-
@delegate.handle_stderr(line, line_no)
|
109
|
-
|
110
|
-
@delegate.handle_stdout(line, line_no)
|
107
|
+
if line_no == 0 && line.start_with?('ssh') && @delegate.respond_to?(:handle_stderr)
|
108
|
+
@delegate.handle_stderr(line, line_no)
|
109
|
+
elsif @delegate.respond_to?(:handle_stdout)
|
110
|
+
@delegate.handle_stdout(line, line_no)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -25,13 +25,13 @@ require 'delegate'
|
|
25
25
|
module Masamune::Commands
|
26
26
|
class HadoopFilesystem < SimpleDelegator
|
27
27
|
DEFAULT_ATTRIBUTES =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
{
|
29
|
+
path: 'hadoop',
|
30
|
+
options: [],
|
31
|
+
extra: [],
|
32
|
+
block: nil,
|
33
|
+
print: false
|
34
|
+
}.freeze
|
35
35
|
|
36
36
|
def initialize(delegate, attrs = {})
|
37
37
|
super delegate
|
@@ -49,7 +49,7 @@ module Masamune::Commands
|
|
49
49
|
args.flatten
|
50
50
|
end
|
51
51
|
|
52
|
-
def handle_stdout(line,
|
52
|
+
def handle_stdout(line, _line_no)
|
53
53
|
@block.call(line) if @block
|
54
54
|
console(line) if @print
|
55
55
|
end
|
@@ -39,17 +39,17 @@ module Masamune::Commands
|
|
39
39
|
|
40
40
|
DEFAULT_ATTRIBUTES =
|
41
41
|
{
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
}
|
42
|
+
path: 'hadoop',
|
43
|
+
options: [],
|
44
|
+
jar: default_hadoop_streaming_jar,
|
45
|
+
input: [],
|
46
|
+
output: nil,
|
47
|
+
mapper: nil,
|
48
|
+
reducer: nil,
|
49
|
+
extra: [],
|
50
|
+
upload: true,
|
51
|
+
quote: false
|
52
|
+
}.freeze
|
53
53
|
|
54
54
|
attr_reader :input
|
55
55
|
|
@@ -61,7 +61,7 @@ module Masamune::Commands
|
|
61
61
|
@input = Array.wrap(@input)
|
62
62
|
end
|
63
63
|
|
64
|
-
# TODO ensure jar/ mapper/reduce exists, warn or remove if output exists
|
64
|
+
# TODO: ensure jar/ mapper/reduce exists, warn or remove if output exists
|
65
65
|
def command_args
|
66
66
|
args = []
|
67
67
|
args << @path
|
@@ -95,10 +95,10 @@ module Masamune::Commands
|
|
95
95
|
path + '/*'
|
96
96
|
end
|
97
97
|
end
|
98
|
-
console(
|
98
|
+
console(format('hadoop_streaming %s -> %s (%s/%s)', @input.join(' '), @output, @mapper, @reducer))
|
99
99
|
end
|
100
100
|
|
101
|
-
def around_execute
|
101
|
+
def around_execute
|
102
102
|
Dir.chdir(filesystem.path(:run_dir)) do
|
103
103
|
yield
|
104
104
|
end
|
@@ -106,10 +106,10 @@ module Masamune::Commands
|
|
106
106
|
|
107
107
|
private
|
108
108
|
|
109
|
-
# FIXME shell quoting is a separate concern
|
109
|
+
# FIXME: shell quoting is a separate concern
|
110
110
|
def quote_arg(arg)
|
111
111
|
out = arg.dup
|
112
|
-
out.gsub!(
|
112
|
+
out.gsub!('\'\t\'', %q('"'\\\\\\\\t'"'))
|
113
113
|
out
|
114
114
|
end
|
115
115
|
end
|
@@ -30,27 +30,27 @@ module Masamune::Commands
|
|
30
30
|
class Hive < SimpleDelegator
|
31
31
|
include Masamune::StringFormat
|
32
32
|
|
33
|
-
PROMPT = 'hive>'
|
33
|
+
PROMPT = 'hive>'.freeze
|
34
34
|
|
35
35
|
DEFAULT_ATTRIBUTES =
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
36
|
+
{
|
37
|
+
path: 'hive',
|
38
|
+
options: [],
|
39
|
+
database: 'default',
|
40
|
+
setup_files: [],
|
41
|
+
schema_files: [],
|
42
|
+
file: nil,
|
43
|
+
exec: nil,
|
44
|
+
output: nil,
|
45
|
+
print: false,
|
46
|
+
block: nil,
|
47
|
+
variables: {},
|
48
|
+
buffer: nil,
|
49
|
+
service: false,
|
50
|
+
delimiter: "\001",
|
51
|
+
csv: false,
|
52
|
+
debug: false
|
53
|
+
}.freeze
|
54
54
|
|
55
55
|
def initialize(delegate, attrs = {})
|
56
56
|
super delegate
|
@@ -83,11 +83,9 @@ module Masamune::Commands
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def before_execute
|
86
|
-
if @file
|
87
|
-
console("hive with file #{@file}")
|
88
|
-
end
|
86
|
+
console("hive with file #{@file}") if @file
|
89
87
|
|
90
|
-
if @debug
|
88
|
+
if @debug && (output = rendered_template || @file)
|
91
89
|
logger.debug("#{output}:\n" + File.read(output))
|
92
90
|
end
|
93
91
|
|
@@ -96,12 +94,10 @@ module Masamune::Commands
|
|
96
94
|
@file = exec_file
|
97
95
|
end
|
98
96
|
|
99
|
-
if @output
|
100
|
-
@buffer = Tempfile.create('masamune_hive_output')
|
101
|
-
end
|
97
|
+
@buffer = Tempfile.create('masamune_hive_output') if @output
|
102
98
|
end
|
103
99
|
|
104
|
-
def around_execute
|
100
|
+
def around_execute
|
105
101
|
Dir.chdir(filesystem.path(:run_dir)) do
|
106
102
|
yield
|
107
103
|
end
|
@@ -115,21 +111,21 @@ module Masamune::Commands
|
|
115
111
|
|
116
112
|
filesystem.move_file_to_file(@buffer.path, @output)
|
117
113
|
ensure
|
118
|
-
File.delete(@buffer.path) if @buffer && @buffer.path && File.
|
114
|
+
File.delete(@buffer.path) if @buffer && @buffer.path && File.exist?(@buffer.path)
|
119
115
|
end
|
120
116
|
|
121
|
-
def handle_stdout(line,
|
117
|
+
def handle_stdout(line, _line_no)
|
122
118
|
if line =~ /\A#{PROMPT}/
|
123
119
|
logger.debug(line)
|
124
|
-
elsif line
|
120
|
+
elsif line.start_with?('Query returned non-zero code:')
|
125
121
|
raise SystemExit, line
|
126
122
|
else
|
127
123
|
@block.call(line) if @block
|
128
124
|
|
129
125
|
if @buffer
|
130
126
|
@buffer.puts(@csv ? line.split(@delimiter).map { |row| encode_row(row) }.to_csv : line)
|
131
|
-
|
132
|
-
console(line)
|
127
|
+
elsif print?
|
128
|
+
console(line)
|
133
129
|
end
|
134
130
|
end
|
135
131
|
end
|
@@ -142,7 +138,7 @@ module Masamune::Commands
|
|
142
138
|
files = @setup_files.map do |path|
|
143
139
|
filesystem.glob_sort(path, order: :basename)
|
144
140
|
end
|
145
|
-
files.flatten.compact.map { |file| {'-i' => file} }
|
141
|
+
files.flatten.compact.map { |file| { '-i' => file } }
|
146
142
|
end
|
147
143
|
|
148
144
|
def command_args_for_file
|
@@ -153,7 +149,7 @@ module Masamune::Commands
|
|
153
149
|
filesystem.copy_file_to_file(@file, remote_file)
|
154
150
|
['-f', remote_file].tap do |args|
|
155
151
|
@variables.each do |key, val|
|
156
|
-
args << ['-d', "#{key
|
152
|
+
args << ['-d', "#{key}=#{val}"]
|
157
153
|
end
|
158
154
|
end
|
159
155
|
end
|
@@ -170,7 +166,7 @@ module Masamune::Commands
|
|
170
166
|
end
|
171
167
|
|
172
168
|
def remote_file
|
173
|
-
@remote_file ||= File.join(filesystem.mktempdir!(:tmp_dir), filesystem.basename(@file)).gsub(/.erb\z/,'')
|
169
|
+
@remote_file ||= File.join(filesystem.mktempdir!(:tmp_dir), filesystem.basename(@file)).gsub(/.erb\z/, '')
|
174
170
|
end
|
175
171
|
|
176
172
|
def exec_file
|
@@ -31,24 +31,24 @@ module Masamune::Commands
|
|
31
31
|
include Masamune::Commands::PostgresCommon
|
32
32
|
|
33
33
|
DEFAULT_ATTRIBUTES =
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
34
|
+
{
|
35
|
+
path: 'psql',
|
36
|
+
options: [],
|
37
|
+
hostname: 'localhost',
|
38
|
+
database: 'postgres',
|
39
|
+
username: 'postgres',
|
40
|
+
pgpass_file: nil,
|
41
|
+
file: nil,
|
42
|
+
exec: nil,
|
43
|
+
input: nil,
|
44
|
+
output: nil,
|
45
|
+
print: false,
|
46
|
+
block: nil,
|
47
|
+
csv: false,
|
48
|
+
variables: {},
|
49
|
+
tuple_output: false,
|
50
|
+
debug: false
|
51
|
+
}.freeze
|
52
52
|
|
53
53
|
def initialize(delegate, attrs = {})
|
54
54
|
super delegate
|
@@ -60,9 +60,7 @@ module Masamune::Commands
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def stdin
|
63
|
-
if @input
|
64
|
-
@stdin ||= StringIO.new(strip_sql(@input))
|
65
|
-
end
|
63
|
+
@stdin ||= StringIO.new(strip_sql(@input)) if @input
|
66
64
|
end
|
67
65
|
|
68
66
|
def interactive?
|
@@ -76,14 +74,14 @@ module Masamune::Commands
|
|
76
74
|
def command_args
|
77
75
|
args = []
|
78
76
|
args << @path
|
79
|
-
args <<
|
80
|
-
args <<
|
81
|
-
args <<
|
77
|
+
args << "--host=#{@hostname}" if @hostname
|
78
|
+
args << "--dbname=#{@database}"
|
79
|
+
args << "--username=#{@username}" if @username
|
82
80
|
args << '--no-password'
|
83
81
|
args << '--set=ON_ERROR_STOP=1'
|
84
82
|
args << @options.map(&:to_a)
|
85
83
|
args << command_args_for_file if @file
|
86
|
-
args <<
|
84
|
+
args << "--output=#{@output}" if @output
|
87
85
|
args << '--no-align' << '--field-separator=,' << '--pset=footer' if @csv
|
88
86
|
args << '--pset=tuples_only' if @tuple_output
|
89
87
|
args.flatten.compact
|
@@ -91,7 +89,7 @@ module Masamune::Commands
|
|
91
89
|
|
92
90
|
def before_execute
|
93
91
|
console("psql with file #{@file}") if @file
|
94
|
-
if @debug
|
92
|
+
if @debug && (output = rendered_template || @file)
|
95
93
|
logger.debug("#{output}:\n" + File.read(output))
|
96
94
|
end
|
97
95
|
|
@@ -101,7 +99,7 @@ module Masamune::Commands
|
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
104
|
-
def handle_stdout(line,
|
102
|
+
def handle_stdout(line, _line_no)
|
105
103
|
if line =~ /\A#{prompt}/
|
106
104
|
logger.debug(line)
|
107
105
|
else
|
@@ -110,12 +108,12 @@ module Masamune::Commands
|
|
110
108
|
end
|
111
109
|
end
|
112
110
|
|
113
|
-
def handle_stderr(line,
|
111
|
+
def handle_stderr(line, _line_no)
|
114
112
|
@error = line.split(/ERROR:\s*/).last if line =~ /ERROR:/
|
115
113
|
logger.debug(line)
|
116
114
|
end
|
117
115
|
|
118
|
-
def failure_message(
|
116
|
+
def failure_message(_status)
|
119
117
|
@error || 'psql failed without error'
|
120
118
|
end
|
121
119
|
|
@@ -134,15 +132,15 @@ module Masamune::Commands
|
|
134
132
|
end
|
135
133
|
|
136
134
|
def command_args_for_simple_file
|
137
|
-
[
|
135
|
+
["--file=#{@file}"].tap do |args|
|
138
136
|
@variables.each do |key, val|
|
139
|
-
args <<
|
137
|
+
args << "--set=#{key}='#{val}'"
|
140
138
|
end
|
141
139
|
end
|
142
140
|
end
|
143
141
|
|
144
142
|
def command_args_for_template
|
145
|
-
[
|
143
|
+
["--file=#{rendered_template}"]
|
146
144
|
end
|
147
145
|
|
148
146
|
def exec_file
|
@@ -29,18 +29,18 @@ module Masamune::Commands
|
|
29
29
|
include Masamune::Commands::PostgresCommon
|
30
30
|
|
31
31
|
DEFAULT_ATTRIBUTES =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
{
|
33
|
+
create_db_path: 'createdb',
|
34
|
+
drop_db_path: 'dropdb',
|
35
|
+
pg_dump_path: 'pg_dump',
|
36
|
+
options: [],
|
37
|
+
hostname: 'localhost',
|
38
|
+
username: 'postgres',
|
39
|
+
pgpass_file: nil,
|
40
|
+
action: nil,
|
41
|
+
database: nil,
|
42
|
+
output: nil
|
43
|
+
}.freeze
|
44
44
|
|
45
45
|
def initialize(delegate, attrs = {})
|
46
46
|
super delegate
|
@@ -53,8 +53,8 @@ module Masamune::Commands
|
|
53
53
|
raise ArgumentError, ':database must be given' unless @database
|
54
54
|
args = []
|
55
55
|
args << command_path
|
56
|
-
args <<
|
57
|
-
args <<
|
56
|
+
args << "--host=#{@hostname}" if @hostname
|
57
|
+
args << "--username=#{@username}" if @username
|
58
58
|
args << '--no-password'
|
59
59
|
args << database
|
60
60
|
args << @options
|
@@ -79,12 +79,13 @@ module Masamune::Commands
|
|
79
79
|
|
80
80
|
def database
|
81
81
|
return @database unless @action == :dump
|
82
|
-
|
82
|
+
"--dbname=#{@database}"
|
83
83
|
end
|
84
84
|
|
85
85
|
def output
|
86
86
|
return unless @action == :dump
|
87
|
-
|
87
|
+
return unless @output
|
88
|
+
"--file=#{@output}"
|
88
89
|
end
|
89
90
|
end
|
90
91
|
end
|
@@ -23,7 +23,7 @@
|
|
23
23
|
module Masamune::Commands
|
24
24
|
module PostgresCommon
|
25
25
|
def command_env
|
26
|
-
{ 'PGOPTIONS'=> '--client-min-messages=warning' }.tap do |env|
|
26
|
+
{ 'PGOPTIONS' => '--client-min-messages=warning' }.tap do |env|
|
27
27
|
if @pgpass_file && File.readable?(@pgpass_file)
|
28
28
|
env['PGPASSFILE'] = @pgpass_file
|
29
29
|
end
|
@@ -35,25 +35,25 @@ module Masamune::Commands
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def around_execute(&block)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
38
|
+
status =
|
39
|
+
if @delegate.respond_to?(:around_execute)
|
40
|
+
@delegate.around_execute(&block)
|
41
|
+
else
|
42
|
+
yield
|
43
|
+
end
|
44
|
+
|
45
|
+
raise "exited with code: #{status.exitstatus}" unless status.success?
|
46
|
+
status
|
47
|
+
rescue => e
|
48
|
+
logger.error(e.to_s)
|
49
|
+
sleep @backoff
|
50
|
+
@retry_count += 1
|
51
|
+
if @retry_count > @retries
|
52
|
+
logger.debug("max retries (#{@retries}) attempted, bailing")
|
53
|
+
OpenStruct.new(success?: false, exitstatus: MAX_RETRY_EXIT_STATUS)
|
54
|
+
else
|
55
|
+
logger.debug("retrying (#{@retry_count}/#{@retries})")
|
56
|
+
retry
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|