bricolage 5.9.0 → 5.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bricolage/commandutils.rb +1 -1
- data/lib/bricolage/jobresult.rb +2 -1
- data/lib/bricolage/psqldatasource.rb +24 -2
- data/lib/bricolage/version.rb +1 -1
- data/libexec/create-lockfile +59 -0
- data/test/home/Gemfile.lock +4 -1
- data/test/home/subsys/d.ct +7 -0
- data/test/home/subsys/rebuild.sql.job +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf741a3e8446d11bfb5e9b0f6dcc891f1cae8495
|
4
|
+
data.tar.gz: c17962a361321f6b19d976f62aace9e7b63544da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c81b950eef56f09a3a1dc7e682a45eabb6c0d25a610d1925ec7409de54f6f11643ddd1153d9d78a25c338160c23c83084293ac7960e1a0634b97bd835cb164d5
|
7
|
+
data.tar.gz: 3068f48c6134aab0c219f826d74b57bc43e077bd486b39140c23925631fd97c9debff45422be35034a82aaa80822c26d14edc4a69249707c38e87f40656e8e1a
|
data/lib/bricolage/jobresult.rb
CHANGED
@@ -47,7 +47,8 @@ module Bricolage
|
|
47
47
|
|
48
48
|
def status
|
49
49
|
if @process_status
|
50
|
-
|
50
|
+
# Process::Status#exitstatus may be nil when the command did not exited normally
|
51
|
+
@process_status.exitstatus || EXIT_FAILURE
|
51
52
|
else
|
52
53
|
case @type
|
53
54
|
when :success then EXIT_SUCCESS
|
@@ -4,6 +4,7 @@ require 'bricolage/sqlstatement'
|
|
4
4
|
require 'bricolage/commandutils'
|
5
5
|
require 'bricolage/postgresconnection'
|
6
6
|
require 'bricolage/exception'
|
7
|
+
require 'pathname'
|
7
8
|
|
8
9
|
module Bricolage
|
9
10
|
|
@@ -243,12 +244,33 @@ module Bricolage
|
|
243
244
|
|
244
245
|
def vacuum_if(enable_vacuum, enable_vacuum_sort, target = '${dest_table}')
|
245
246
|
if enable_vacuum
|
246
|
-
|
247
|
+
serialize_vacuum {
|
248
|
+
exec SQLStatement.for_string("vacuum #{target};")
|
249
|
+
}
|
247
250
|
elsif enable_vacuum_sort
|
248
|
-
|
251
|
+
serialize_vacuum {
|
252
|
+
exec SQLStatement.for_string("vacuum sort only #{target};")
|
253
|
+
}
|
249
254
|
end
|
250
255
|
end
|
251
256
|
|
257
|
+
DEFAULT_VACUUM_LOCK_FILE = '/tmp/bricolage.vacuum.lock'
|
258
|
+
DEFAULT_VACUUM_LOCK_TIMEOUT = 3600 # 60min
|
259
|
+
|
260
|
+
def serialize_vacuum
|
261
|
+
if ENV['BRICOLAGE_VACUUM_LOCK']
|
262
|
+
path, tm = ENV['BRICOLAGE_VACUUM_LOCK'].split(':', 2)
|
263
|
+
timeout = tm.to_i
|
264
|
+
else
|
265
|
+
path = DEFAULT_VACUUM_LOCK_FILE
|
266
|
+
timeout = DEFAULT_VACUUM_LOCK_TIMEOUT
|
267
|
+
end
|
268
|
+
lock_file_cmd = Pathname(__FILE__).parent.parent.parent + 'libexec/create-lockfile'
|
269
|
+
exec SQLStatement.for_string "\\! #{lock_file_cmd} #{path} #{timeout}"
|
270
|
+
yield
|
271
|
+
exec SQLStatement.for_string "\\! rm #{path}"
|
272
|
+
end
|
273
|
+
|
252
274
|
def analyze_if(enabled, target = '${dest_table}')
|
253
275
|
exec SQLStatement.for_string("analyze #{target};") if enabled
|
254
276
|
end
|
data/lib/bricolage/version.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
DEFAULT_TIMEOUT = 900 # 15 minutes
|
4
|
+
MINIMUM_TIMEOUT = 1
|
5
|
+
|
6
|
+
def main
|
7
|
+
unless ARGV.size == 2
|
8
|
+
$stderr.puts "Usage: #{$0} PATH TIMEOUT_SEC"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
path, tm = ARGV
|
12
|
+
timeout = [tm.to_i, MINIMUM_TIMEOUT].max
|
13
|
+
create_lock_file path, timeout
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_lock_file(path, timeout)
|
17
|
+
start_time = Time.now
|
18
|
+
print_message "trying to create lock file: #{path} (psql #{parent_is_psql? ? 'detected' : 'NOT detected'})"
|
19
|
+
begin
|
20
|
+
File.open(path, File::WRONLY | File::CREAT | File::EXCL) {|f|
|
21
|
+
f.puts "#{Time.now}: created by process \##{Process.ppid}"
|
22
|
+
}
|
23
|
+
rescue Errno::EEXIST
|
24
|
+
if Time.now - start_time > timeout
|
25
|
+
emit_error_to_psql
|
26
|
+
error_exit "could not create lock file: #{path} (timeout #{timeout} seconds)"
|
27
|
+
end
|
28
|
+
sleep 3
|
29
|
+
retry
|
30
|
+
rescue
|
31
|
+
emit_error_to_psql
|
32
|
+
raise
|
33
|
+
end
|
34
|
+
print_message "lock file created: #{path}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def emit_error_to_psql
|
38
|
+
# psql does not stop on error of external command,
|
39
|
+
# we must explicitly stop that.
|
40
|
+
if parent_is_psql?
|
41
|
+
Process.kill 'TERM', Process.ppid
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def parent_is_psql?
|
46
|
+
# psql set this environment variable
|
47
|
+
!!ENV['PGSYSCONFDIR']
|
48
|
+
end
|
49
|
+
|
50
|
+
def error_exit(msg)
|
51
|
+
$stderr.puts "#{$0}: error: #{msg}"
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
|
55
|
+
def print_message(msg)
|
56
|
+
$stderr.puts "#{Time.now}: #{msg}"
|
57
|
+
end
|
58
|
+
|
59
|
+
main
|
data/test/home/Gemfile.lock
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bricolage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.9.
|
4
|
+
version: 5.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minero Aoki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/bricolage/tddatasource.rb
|
154
154
|
- lib/bricolage/variables.rb
|
155
155
|
- lib/bricolage/version.rb
|
156
|
+
- libexec/create-lockfile
|
156
157
|
- libexec/sqldump
|
157
158
|
- libexec/sqldump.Darwin
|
158
159
|
- libexec/sqldump.Linux
|
@@ -166,8 +167,10 @@ files:
|
|
166
167
|
- test/home/data/20141002-1355_02.txt
|
167
168
|
- test/home/put.sh
|
168
169
|
- test/home/revert.sh
|
170
|
+
- test/home/subsys/d.ct
|
169
171
|
- test/home/subsys/load_test.ct
|
170
172
|
- test/home/subsys/load_test.job
|
173
|
+
- test/home/subsys/rebuild.sql.job
|
171
174
|
- test/home/subsys/separated.job
|
172
175
|
- test/home/subsys/separated.sql
|
173
176
|
- test/home/subsys/unified.jobnet
|