synchronised_migration 2.1.0 → 2.1.1
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/CHANGELOG.md +4 -0
- data/lib/synchronised_migration/main.rb +10 -9
- data/lib/synchronised_migration/version.rb +1 -1
- data/spec/synchronised_migration/main_spec.rb +37 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc7b4ada6d890ac183de30b375e6ead7de8dde32827aa870808552420637a006
|
4
|
+
data.tar.gz: 1826cd77772547266f1dcf309a52574960aa0fdd6efb96a148264ad995979b08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5748c0d00c031d6bea8400d598c39f97a6bde99eebfe9273e018fd346ca79186a809ef6f16d9ce6a4213a583e88b7f1fce3e713fd2a9dc40a7adb70340016a0c
|
7
|
+
data.tar.gz: 18442e4f7ddcbdb497af3a05852b59677840871c24844945ddf4da3fca9a5edf2857f6090c5c01067d69c88ee7098a7e5e0ca5f8632e273399c614b537c36de2
|
data/CHANGELOG.md
CHANGED
@@ -32,10 +32,11 @@ class SynchronisedMigration::Main
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def execute
|
35
|
+
return Result.ok if migration_already_completed?
|
35
36
|
return Result.fail 'Halting the script because the previous migration failed.' if previous_failed?
|
36
37
|
mark_failed
|
37
|
-
migrate
|
38
|
-
return Result.fail 'Migration failed.'
|
38
|
+
migration_success = migrate
|
39
|
+
return Result.fail 'Migration failed.' unless migration_success
|
39
40
|
mark_successful
|
40
41
|
remove_fail_marker
|
41
42
|
return Result.ok
|
@@ -67,20 +68,20 @@ class SynchronisedMigration::Main
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def migrate
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
if with_clean_env?
|
72
|
+
Bundler.with_original_env do
|
73
|
+
Kernel.system target_command
|
74
|
+
end
|
75
|
+
else
|
76
|
+
Kernel.system target_command
|
73
77
|
end
|
78
|
+
$?.success?
|
74
79
|
end
|
75
80
|
|
76
81
|
def with_clean_env?
|
77
82
|
not ENV.fetch('WITH_CLEAN_BUNDLER_ENV', '').empty?
|
78
83
|
end
|
79
84
|
|
80
|
-
def migration_failed?
|
81
|
-
not $?.success?
|
82
|
-
end
|
83
|
-
|
84
85
|
def target_command
|
85
86
|
ENV.fetch 'SYNCHRONISED_COMMAND', 'bin/launch/migrate'
|
86
87
|
end
|
@@ -10,7 +10,8 @@ describe SynchronisedMigration::Main do
|
|
10
10
|
let(:redlock) { double }
|
11
11
|
let(:fail_marker_value) { nil }
|
12
12
|
let(:success_marker_value) { nil }
|
13
|
-
let(:
|
13
|
+
let(:version_suffix) { 'bork' }
|
14
|
+
let(:set_version_suffix) { ENV['REDLOCK_VERSION_SUFFIX'] = version_suffix }
|
14
15
|
let(:time_value) { double(to_i: 123456789) }
|
15
16
|
|
16
17
|
before do
|
@@ -19,8 +20,24 @@ describe SynchronisedMigration::Main do
|
|
19
20
|
subject.instance.instance_variable_set :@redis, nil
|
20
21
|
subject.instance.instance_variable_set :@redlock, nil
|
21
22
|
|
23
|
+
allow(subject.instance).to receive(:execute).and_call_original
|
24
|
+
allow(subject.instance).to receive(:migrate).and_call_original
|
25
|
+
|
22
26
|
allow(Redis).to receive(:new).and_return(redis)
|
23
|
-
allow(redis).to receive(:get)
|
27
|
+
allow(redis).to receive(:get) { |key|
|
28
|
+
case key
|
29
|
+
when "migration-failed-#{version_suffix}"
|
30
|
+
fail_marker_value
|
31
|
+
when "migration-failed"
|
32
|
+
fail_marker_value
|
33
|
+
when "migration-success-#{version_suffix}"
|
34
|
+
success_marker_value
|
35
|
+
when "migration-success"
|
36
|
+
success_marker_value
|
37
|
+
else
|
38
|
+
raise "invalid key for redis get: #{key}"
|
39
|
+
end
|
40
|
+
}
|
24
41
|
allow(redis).to receive(:set)
|
25
42
|
allow(redis).to receive(:del)
|
26
43
|
|
@@ -62,6 +79,24 @@ describe SynchronisedMigration::Main do
|
|
62
79
|
expect(redlock).not_to have_received(:lock!)
|
63
80
|
end
|
64
81
|
end
|
82
|
+
|
83
|
+
context 'executing in lock waiter' do
|
84
|
+
let(:result2) { subject.call }
|
85
|
+
|
86
|
+
before do
|
87
|
+
# Note: bypasses the first success flag check so it can enter lock.
|
88
|
+
expect(result).to be_success
|
89
|
+
allow(redis).to receive(:get).and_return(nil, '1')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'early exits and does not execute again', :aggregate_failures do
|
93
|
+
expect(result2).to be_success
|
94
|
+
expect(redlock).to have_received(:lock!).exactly(2).times
|
95
|
+
expect(Kernel).to have_received(:system).exactly(1).times
|
96
|
+
expect(subject.instance).to have_received(:execute).exactly(2).times
|
97
|
+
expect(subject.instance).to have_received(:migrate).exactly(1).times
|
98
|
+
end
|
99
|
+
end
|
65
100
|
end
|
66
101
|
|
67
102
|
context 'when require a clean Bundler environment' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synchronised_migration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alvin Yim
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-08-
|
12
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redlock
|