themigrator 0.1.7 → 0.1.9
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/lib/themigrator/migration_progress.rb +91 -6
- data/lib/themigrator/migrator.rb +11 -2
- data/lib/themigrator/version.rb +1 -1
- 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: d8dbb153310083d3935db37f8662511c357c24c4
|
4
|
+
data.tar.gz: 1f33da2750d76e79976c7d1c7e3c53e595dde1c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab7b20ff28c285ff0717580a94466dea113d3ed4522f019dbe08f0cb6b4d2b00265139f9eca4af870afca9a56330a796f571d1032f22cf9076fdf0b009a9500
|
7
|
+
data.tar.gz: 3ea69f65eaee4f40143d6ac4a4749a758d40d5e8af8296aea79d084ecc2453ef39ed91523e33e1a157b8bb25259305ac7be05f16ebe0122089d47a5722ce0b13
|
@@ -1,29 +1,114 @@
|
|
1
|
-
|
1
|
+
require 'time'
|
2
|
+
require 'themigrator/migration'
|
2
3
|
|
3
4
|
module Themigrator
|
5
|
+
# MigrationProgress takes the main log fails and parse it.
|
4
6
|
class MigrationProgress
|
5
7
|
include Logger
|
8
|
+
|
9
|
+
attr_reader :roles, :run_id, :start_time, :pid, :status, :current_action, :actions
|
6
10
|
|
7
11
|
|
8
|
-
def initialize(dir, run_id)
|
12
|
+
def initialize(dir, run_id, has_roles_cbk: nil, start_action_cbk: nil )
|
9
13
|
@dir, @run_id = dir, run_id
|
10
14
|
@log_file_path = main_log_path(dir, run_id)
|
15
|
+
@roles = []
|
16
|
+
@current_action = nil
|
17
|
+
@cbks = {
|
18
|
+
has_roles: has_roles_cbk,
|
19
|
+
start_action: start_action_cbk
|
20
|
+
}
|
21
|
+
@actions = Hash.new do |h,k|
|
22
|
+
h[k] = {
|
23
|
+
start_time: nil,
|
24
|
+
roles: Hash.new {|rh,rk| rh[rk] = {} },
|
25
|
+
end_time: nil}
|
26
|
+
end
|
27
|
+
|
11
28
|
start_log_parser
|
12
29
|
end
|
13
30
|
|
14
31
|
private
|
15
32
|
|
16
33
|
def start_log_parser
|
34
|
+
IO.foreach(@log_file_path) do |line|
|
35
|
+
process_line(line)
|
36
|
+
end
|
37
|
+
rescue EOFError
|
38
|
+
end
|
17
39
|
|
18
|
-
File.open(@log_file_path, "r") do |f|
|
19
|
-
f.readline
|
20
|
-
raise File.read(@log_file_path)
|
21
40
|
|
41
|
+
def call_cbk(name, *args)
|
42
|
+
cbk = @cbks[name]
|
43
|
+
cbk.call(self) if cbk
|
44
|
+
end
|
22
45
|
|
46
|
+
|
47
|
+
def process_line(line)
|
48
|
+
line.strip!
|
49
|
+
case line
|
50
|
+
when /^# Logfile created on ([0-9-]+) ([0-9:]+) /
|
51
|
+
@start_time = Time.parse("#{$1} #{$2}")
|
52
|
+
else
|
53
|
+
process_log_entry(line)
|
23
54
|
end
|
55
|
+
call_cbk(:new_line, line)
|
56
|
+
end
|
24
57
|
|
25
|
-
|
58
|
+
def process_log_entry(line)
|
59
|
+
time, line = extract_time(line)
|
60
|
+
scripts = Themigrator::Migration::SCRIPTS.join("|")
|
61
|
+
case line
|
62
|
+
when /start PID=(\d+)/
|
63
|
+
@pid = $1.to_i
|
64
|
+
when /roles: (.+)/
|
65
|
+
@roles = $1.strip.split.sort
|
66
|
+
when /(#{scripts}) => start/
|
67
|
+
action = $1.to_sym
|
68
|
+
@current_action = action
|
69
|
+
@actions[action][:start_time] = time
|
70
|
+
when /(#{scripts}) => (done|fail) \(([0-9\.]+) ms\)/
|
71
|
+
action = $1.to_sym
|
72
|
+
success = to_success($2)
|
73
|
+
run_time = $3.to_f
|
74
|
+
|
75
|
+
@actions[action][:end_time] = time
|
76
|
+
@actions[action][:run_time] = run_time
|
77
|
+
@actions[action][:success] = success
|
78
|
+
@current_action = nil
|
79
|
+
|
80
|
+
when /(#{scripts}) \| (.*) => start/
|
81
|
+
action = $1.to_sym
|
82
|
+
role = $2
|
83
|
+
@actions[action][:roles][role][:start_time] = time
|
84
|
+
when /(#{scripts}) \| (.*) => exited with (\d+) \(([0-9\.]+) ms\)/
|
85
|
+
action = $1.to_sym
|
86
|
+
role = $2
|
87
|
+
exitcode = $3.to_i
|
88
|
+
success = exitcode == 0
|
89
|
+
run_time = $4.to_f
|
90
|
+
@actions[action][:roles][role][:end_time] = time
|
91
|
+
@actions[action][:roles][role][:exitcode] = exitcode
|
92
|
+
@actions[action][:roles][role][:success] = success
|
93
|
+
@actions[action][:roles][role][:run_time] = run_time
|
94
|
+
else
|
95
|
+
raise line
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def extract_time(line)
|
100
|
+
line =~ /^([0-9-]+) ([0-9:]+) (.*)/
|
101
|
+
time = Time.parse("#{$1} #{$2}")
|
102
|
+
line = $3
|
103
|
+
return time, line.strip
|
104
|
+
end
|
105
|
+
|
106
|
+
def rollback?
|
107
|
+
@actions.keys.include?("rollback")
|
108
|
+
end
|
26
109
|
|
110
|
+
def to_success(val)
|
111
|
+
val == "done" ? true : false
|
27
112
|
end
|
28
113
|
|
29
114
|
end
|
data/lib/themigrator/migrator.rb
CHANGED
@@ -12,7 +12,8 @@ module Themigrator
|
|
12
12
|
def initialize(dir)
|
13
13
|
@dir = dir
|
14
14
|
@runned_roles = []
|
15
|
-
@
|
15
|
+
@start_time = Time.now
|
16
|
+
@run_id = @start_time.strftime("%Y-%m-%d-%H:%M:%S")
|
16
17
|
end
|
17
18
|
|
18
19
|
def migrate!
|
@@ -27,12 +28,16 @@ module Themigrator
|
|
27
28
|
each_action do |action|
|
28
29
|
if !run_action_and_wait(action)
|
29
30
|
did_it_work = false
|
30
|
-
|
31
|
+
run_action_and_wait("rollback")
|
31
32
|
return -1
|
32
33
|
end
|
33
34
|
end
|
34
35
|
close_logger
|
35
36
|
did_it_work
|
37
|
+
ensure
|
38
|
+
@end_time = Time.now
|
39
|
+
msg = did_it_work ? "done" : "fail"
|
40
|
+
log "end => #{msg} (#{run_time * 1000} ms)"
|
36
41
|
end
|
37
42
|
|
38
43
|
private
|
@@ -79,6 +84,10 @@ module Themigrator
|
|
79
84
|
def find_script(role, action)
|
80
85
|
File.join(@dir, role, action)
|
81
86
|
end
|
87
|
+
|
88
|
+
def run_time
|
89
|
+
@end_time - @start_time if @end_time
|
90
|
+
end
|
82
91
|
end
|
83
92
|
|
84
93
|
end
|
data/lib/themigrator/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: themigrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillermo Álvarez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|