patches 3.2.0 → 3.3.0

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
  SHA256:
3
- metadata.gz: ee9d2a7ad9476606358ef1f9d07d4357c51257a2553677310191b0969980ef1b
4
- data.tar.gz: bd02a484a3814d0a6ef0eb10b9f391e17c6ea0dfbd84ad83ff3bb18aab514e26
3
+ metadata.gz: 31f20fe803ffb8762b4ebdbdacb5b33564d67eaa24505ffb8fdd25fc88a6198c
4
+ data.tar.gz: c7fbbb497911d30dd73555a77f8ea946788de6b43110df7afcf6e680f9a349a3
5
5
  SHA512:
6
- metadata.gz: 240517aa974013c588bbda1f94dcd387ba4bc4175c8c875cec6a640bc22169ed7e6ef73177d1fc449923f5216c90705fcf1abcad06c7f035ad52aa0e79dcceb9
7
- data.tar.gz: bf675bf446a70b10796e4484cdbd69d0e79ef4e1d9c203851fced9b7089a633fedfabbd3ca26c67361fa3acde9da40560c0f8849e80447552f0586f2a4d7c07a
6
+ metadata.gz: 2b2674ce8e4f2deb2f856e67c32d381bf4007729fad286179b89c0c982c8991b58072c59de133485ea7d9a40071df36778198037569a496a60fa25f4371ce6e1
7
+ data.tar.gz: 5fee7f04b02862424097a26e51fe6ad376e885637e67aa90f3986942457494900646426a393f3b1a8946fc3fbb748a8bed89619a9cd7e28a2278151a0eefbc34
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+
9
+ ## [3.3.0] - 2020-07-20
10
+ ### Added
11
+ - Application version constraints
12
+
8
13
  ## [3.2.0] - 2020-07-16
9
14
  ### Added
10
15
  - Added `Patches::Worker` extra parameters to support forward compatibility with the upcoming releases
@@ -26,7 +26,7 @@ If you would like to run the patches asynchronously, or would like them to notif
26
26
  your Slack channel when they fail or succeed, you need to set up
27
27
  an initializer to set those options.
28
28
 
29
- ```Ruby
29
+ ```ruby
30
30
  Patches::Config.configure do |config|
31
31
  config.use_sidekiq = true
32
32
 
@@ -44,7 +44,7 @@ end
44
44
  If you are using the Apartment gem, you can run the patches for each tenant in parallel.
45
45
  Just set the config ```sidekiq_parallel``` to ```true``` and you're good to go.
46
46
 
47
- ```
47
+ ```ruby
48
48
  Patches::Config.configure do |config|
49
49
  config.use_sidekiq = true
50
50
  config.sidekiq_parallel = true
@@ -54,6 +54,23 @@ end
54
54
  *Note:* Make sure your sidekiq queue is able to process concurrent jobs.
55
55
  You can use ```config.sidekiq_options``` to customise it.
56
56
 
57
+ ### Application version verification
58
+
59
+ In environments where a rolling update of sidekiq workers is performed during the deployment, multiple versions of the application run at the same time. If a Patches job is scheduled by the new application version during the rolling update, there is a possibility that it can be executed by the old application version, which will not have all the required patch files.
60
+
61
+ To prevent this case, set the application version in the config:
62
+
63
+ ```ruby
64
+ Patches::Config.configure do |config|
65
+ revision_file_path = Rails.root.join('REVISION')
66
+
67
+ if File.exist?(revision_file_path)
68
+ config.application_version = File.read(revision_file_path)
69
+ config.retry_after_version_mismatch_in = 1.minute
70
+ end
71
+ end
72
+ ```
73
+
57
74
  ## Creating Patches
58
75
 
59
76
  Generate a patch
@@ -76,7 +93,7 @@ update the run method and then execute
76
93
 
77
94
  Generate patch with specs
78
95
 
79
- ```
96
+ ```bash
80
97
  bundle exec rails g patches:patch PreferenceUpdate --specs=true
81
98
  ```
82
99
 
@@ -108,7 +125,7 @@ after sidekiq restarts, otherwise there is no guarentee the tasks will run.
108
125
  If a patch requires data assets, you could use S3 to store the file.
109
126
  If credentials are defined in env vars, as per https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#id1
110
127
 
111
- ```
128
+ ```ruby
112
129
  require 'aws-sdk-s3'
113
130
  Aws::S3::Client.new.get_object(bucket: @bucket_name, key: filename, response_target: destination)
114
131
  ```
@@ -14,8 +14,15 @@ module Patches
14
14
  end
15
15
 
16
16
  class Configuration
17
- attr_accessor :use_sidekiq, :sidekiq_queue, :sidekiq_options,
18
- :sidekiq_parallel, :use_slack, :slack_options
17
+ attr_accessor \
18
+ :application_version,
19
+ :retry_after_version_mismatch_in,
20
+ :sidekiq_options,
21
+ :sidekiq_parallel,
22
+ :sidekiq_queue,
23
+ :slack_options,
24
+ :use_sidekiq,
25
+ :use_slack
19
26
 
20
27
  def initialize
21
28
  @sidekiq_queue = 'default'
@@ -25,6 +32,10 @@ module Patches
25
32
  @sidekiq_options ||= { retry: false, queue: sidekiq_queue }
26
33
  end
27
34
 
35
+ def retry_after_version_mismatch_in
36
+ @retry_after_version_mismatch_in ||= 1.minute
37
+ end
38
+
28
39
  def slack_channel
29
40
  slack_options[:channel]
30
41
  end
@@ -1,6 +1,6 @@
1
1
  module Patches
2
2
  MAJOR = 3
3
- MINOR = 2
3
+ MINOR = 3
4
4
  PATCH = 0
5
5
  VERSION = [MAJOR, MINOR, PATCH].compact.join(".").freeze
6
6
  end
@@ -6,6 +6,18 @@ class Patches::Worker
6
6
  sidekiq_options Patches::Config.configuration.sidekiq_options
7
7
 
8
8
  def perform(runner, params = {})
9
- runner.constantize.new.perform
9
+ if valid_application_version?(params)
10
+ runner.constantize.new.perform
11
+ else
12
+ self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, runner, params)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def valid_application_version?(params)
19
+ return true unless params['application_version']
20
+ return true unless Patches::Config.configuration.application_version
21
+ Patches::Config.configuration.application_version == params['application_version']
10
22
  end
11
23
  end
@@ -8,7 +8,10 @@ namespace :patches do
8
8
  end
9
9
 
10
10
  if defined?(Sidekiq) && Patches::Config.configuration.use_sidekiq
11
- Patches::Worker.perform_async(runner)
11
+ Patches::Worker.perform_async(
12
+ runner,
13
+ application_version: Patches::Config.configuration.application_version
14
+ )
12
15
  else
13
16
  runner.new.perform
14
17
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.8"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "sqlite3", "~> 1.3.5"
28
- spec.add_development_dependency "rspec-rails", "~> 3.2.0"
28
+ spec.add_development_dependency "rspec-rails", "~> 4.0.0"
29
29
  spec.add_development_dependency "capybara", "~> 2.3.0"
30
30
  spec.add_development_dependency "generator_spec", "~> 0.9.0"
31
31
  spec.add_development_dependency "simplecov", "~> 0.10"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patches
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JobReady
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.2.0
89
+ version: 4.0.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.2.0
96
+ version: 4.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: capybara
99
99
  requirement: !ruby/object:Gem::Requirement