synchronised_migration 0.1.0.pre.alpha.1 → 0.1.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ab84276b5cbc3b6a059da59e59c414496f72a69
4
- data.tar.gz: ba49512428c7d3554fbafa2d98b6746204f3d4ad
3
+ metadata.gz: 9000c0002dc564ee9f7cfaf21709223579272438
4
+ data.tar.gz: 1872e38d3548032b9f8fcc20451a00040034baf6
5
5
  SHA512:
6
- metadata.gz: f18218af70a990a21ccdb7a88944bcf5482d56fc84b9181b52b48ee60339d1b412f27dcf91922849d617e59f0ca4dcc8429b8c5cfea32eef707d4286633c489c
7
- data.tar.gz: 3dc0653bc15b35736138bacbdb9752e76589f571657966bc0b5ef641e1f67350d1fa4b201690320c54aa00fcc38001e74ce44c3cd8d10c262d21bbfca67c0180
6
+ metadata.gz: e8ea7ef4379e2759718215ecfe675f8490c965aa32f1e1ad7a057e7b4282a37402f6df8aad4924d44c5f819cd0f928c0cdd8be4ef3c3556813b40e86939aa5c1
7
+ data.tar.gz: e5b8f5c075a49a142cbfa03af6e89bff4f5303833d773d72e73c43d711cc7bfae21dbfc5850da71a95326afcc00b386210b886c493e5199a2c9bdf9f0ba6df3a
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  /.bundle
2
2
  /vendor
3
3
  /coverage
4
+ /*.gem
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
- SYNC_RAKE_TASK=launch:migrate
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
- Rake::Task[target_rake_task].invoke
52
+ Kernel.system target_command
52
53
  end
53
54
 
54
- def target_rake_task
55
- ENV.fetch 'SYNC_RAKE_TASK', 'launch:migrate'
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:://%s:%s/%s',
78
+ 'redis://%s:%s/%s',
74
79
  RedisConfig.get[:host],
75
80
  RedisConfig.get[:port],
76
81
  RedisConfig.get[:db]
@@ -1,3 +1,3 @@
1
1
  module SynchronisedMigration
2
- VERSION = '0.1.0-alpha.1'
2
+ VERSION = '0.1.0-alpha.2'
3
3
  end
@@ -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
- stub_const 'Rake', Module.new
27
- stub_const 'Rake::Task', { 'launch:migrate' => rake_task }
28
-
29
- allow(rake_task).to receive(:invoke)
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(rake_task).to have_received(:invoke)
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(rake_task).not_to have_received(:invoke)
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
- allow(rake_task).to receive(:invoke) do
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 { result }.to raise_error('An error message')
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.1
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 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redlock