synchronised_migration 0.1.0.pre.alpha.1 → 0.1.0.pre.alpha.2
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/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/synchronised_migration/main.rb +9 -4
- data/lib/synchronised_migration/version.rb +1 -1
- data/spec/synchronised_migration/main_spec.rb +8 -11
- 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: 9000c0002dc564ee9f7cfaf21709223579272438
|
4
|
+
data.tar.gz: 1872e38d3548032b9f8fcc20451a00040034baf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ea7ef4379e2759718215ecfe675f8490c965aa32f1e1ad7a057e7b4282a37402f6df8aad4924d44c5f819cd0f928c0cdd8be4ef3c3556813b40e86939aa5c1
|
7
|
+
data.tar.gz: e5b8f5c075a49a142cbfa03af6e89bff4f5303833d773d72e73c43d711cc7bfae21dbfc5850da71a95326afcc00b386210b886c493e5199a2c9bdf9f0ba6df3a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,7 @@ RedisConfig.get[:db] # 0
|
|
26
26
|
You may override these settings through environment variables.
|
27
27
|
|
28
28
|
```
|
29
|
-
|
29
|
+
SYNCHRONISED_COMMAND=bin/launch/migrate
|
30
30
|
REDLOCK_TIMEOUT_MS=3600000
|
31
31
|
REDLOCK_RETRY_DELAY_MS=200
|
32
32
|
REDLOCK_LOCK_KEY=migration-in-progress
|
@@ -30,6 +30,7 @@ class SynchronisedMigration::Main
|
|
30
30
|
return Result.new 'Halting the script because the previous migration failed.' if previous_failed?
|
31
31
|
mark_failed
|
32
32
|
migrate
|
33
|
+
return Result.new 'Migration failed.' if migration_failed?
|
33
34
|
remove_fail_marker
|
34
35
|
Result.new
|
35
36
|
end
|
@@ -48,11 +49,15 @@ class SynchronisedMigration::Main
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def migrate
|
51
|
-
|
52
|
+
Kernel.system target_command
|
52
53
|
end
|
53
54
|
|
54
|
-
def
|
55
|
-
|
55
|
+
def migration_failed?
|
56
|
+
not $?.success?
|
57
|
+
end
|
58
|
+
|
59
|
+
def target_command
|
60
|
+
ENV.fetch 'SYNCHRONISED_COMMAND', 'bin/launch/migrate'
|
56
61
|
end
|
57
62
|
|
58
63
|
def redis
|
@@ -70,7 +75,7 @@ class SynchronisedMigration::Main
|
|
70
75
|
|
71
76
|
def redis_url
|
72
77
|
sprintf(
|
73
|
-
'redis
|
78
|
+
'redis://%s:%s/%s',
|
74
79
|
RedisConfig.get[:host],
|
75
80
|
RedisConfig.get[:port],
|
76
81
|
RedisConfig.get[:db]
|
@@ -9,7 +9,6 @@ describe SynchronisedMigration::Main do
|
|
9
9
|
let(:redis) { double }
|
10
10
|
let(:redlock) { double }
|
11
11
|
let(:fail_marker_value) { nil }
|
12
|
-
let(:rake_task) { double }
|
13
12
|
|
14
13
|
before do
|
15
14
|
subject.instance.instance_variable_set :@redis, nil
|
@@ -23,10 +22,10 @@ describe SynchronisedMigration::Main do
|
|
23
22
|
allow(Redlock::Client).to receive(:new).and_return(redlock)
|
24
23
|
allow(redlock).to receive(:lock!) { |lock_key, timeout, &block| block.call }
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
allow(Kernel).to receive(:system).and_wrap_original { |method, *args|
|
26
|
+
next if args == [ 'bin/launch/migrate' ]
|
27
|
+
method.call *args
|
28
|
+
}
|
30
29
|
|
31
30
|
stub_const(
|
32
31
|
'RedisConfig', double(
|
@@ -45,7 +44,7 @@ describe SynchronisedMigration::Main do
|
|
45
44
|
expect(redlock).to have_received(:lock!)
|
46
45
|
expect(redis).to have_received(:get).with('migration-failed')
|
47
46
|
expect(redis).to have_received(:set).with('migration-failed', 1)
|
48
|
-
expect(
|
47
|
+
expect(Kernel).to have_received(:system)
|
49
48
|
expect(redis).to have_received(:del).with('migration-failed')
|
50
49
|
end
|
51
50
|
end
|
@@ -55,19 +54,17 @@ describe SynchronisedMigration::Main do
|
|
55
54
|
|
56
55
|
it "doesn't execute the migration" do
|
57
56
|
expect(result).not_to be_success
|
58
|
-
expect(
|
57
|
+
expect(Kernel).not_to have_received(:system)
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
61
|
context 'when the task crashed' do
|
63
62
|
before do
|
64
|
-
|
65
|
-
fail 'An error message'
|
66
|
-
end
|
63
|
+
allow_any_instance_of(Process::Status).to receive(:success?).and_return(false)
|
67
64
|
end
|
68
65
|
|
69
66
|
it 'marks the failure in Redis' do
|
70
|
-
expect
|
67
|
+
expect(result).not_to be_success
|
71
68
|
expect(redis).to have_received(:set).with('migration-failed', 1)
|
72
69
|
expect(redis).not_to have_received(:del)
|
73
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synchronised_migration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha.
|
4
|
+
version: 0.1.0.pre.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alvin Yim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redlock
|