patches 2.4.1 → 3.5.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: a726ce30a4830757598e3c8e1a418ae177496782f61b2863709389be96c4d086
4
- data.tar.gz: 83c927ddd30bf534d0925c9962faea4a1b8ae384ed0f726997eb0c595a0f8312
3
+ metadata.gz: 00a5a2af4415f00b094e7a41da3c17ddb61d17c9e23987aa16dddf789aec7794
4
+ data.tar.gz: 3125f98fb50e54c658a2be70a369f2627c138fb50c1ba8f9c417c5139a144f56
5
5
  SHA512:
6
- metadata.gz: 5ca1c096b455735c6ac1dd2b2bd246126fb1fc45d0d253d099234b3fd4bc3f22f13dec67d1c2708efea16afdbe7d25d4b57c61743540803c9bb7097122e7d8f4
7
- data.tar.gz: e6495c336cc87c106e7943ec7fbd2798aaa8010bda3a024357f7bbf4b4fcac1b5c703db81e166fc3451bac96e699614118eda1027306dfb4462b97540700d21c
6
+ metadata.gz: d57ccb9aca3ab7c179dce484a7e2021631ef0c70d86bc00f73c921636184d42e372a85a6ab321e599731c72dfcf40716b52a234d7c33bebb9ba8d102d64ba212
7
+ data.tar.gz: ed55b40b2ebb05dc6db25c7ccc07a09f774360816fe39a21e1b79903c306bcdd4a4a5b82b2db262966224e1f712656b8eac7bb423f93db004d59d63af26a6763
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.5.0] - 2020-07-22
10
+ ### Added
11
+ - Enable application version constraint support on `Patches::TenantWorker`
12
+
13
+ ## [3.4.0] - 2020-07-22
14
+ ### Added
15
+ - `Patches::TenantWorker` application version constraint forward compatibility
16
+
17
+ ## [3.3.0] - 2020-07-20
18
+ ### Added
19
+ - Application version constraints
20
+
21
+ ## [3.2.0] - 2020-07-16
22
+ ### Added
23
+ - Added `Patches::Worker` extra parameters to support forward compatibility with the upcoming releases
24
+
25
+ ## [3.1.0] - 2019-11-25
26
+ ### Fixed
27
+ - Gem compatibility with Apartment 2
28
+
29
+ ## [3.0.1] - 2018-11-19
30
+ ### Added
31
+ - Set icon_emoji of posted slack message to :dog:
32
+
33
+ ## [3.0.0] - 2018-11-19
34
+ ### Removed
35
+ - Hipchat is no longer supported
36
+
9
37
  ## [2.4.1] - 2018-09-19
10
38
  ### Changed
11
39
  - Corrected gem ownership and authors.
File without changes
@@ -23,21 +23,13 @@ bundle exec rake db:migrate
23
23
  ## Configuration
24
24
 
25
25
  If you would like to run the patches asynchronously, or would like them to notify
26
- your hipchat room or Slack channel when they fail or succeed, you need to set up
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
 
33
- config.use_hipchat = true
34
- config.hipchat_options = {
35
- api_token: ENV['HIPCHAT_TOKEN'],
36
- room: ENV['HIPCHAT_ROOM'],
37
- user: ENV['HIPCHAT_USERNAME'], # maximum of 15 characters
38
- api_version: 'v1', # optional
39
- }
40
-
41
33
  config.use_slack = true
42
34
  config.slack_options = {
43
35
  webhook_url: ENV['SLACK_WEBHOOK_URL'],
@@ -52,7 +44,7 @@ end
52
44
  If you are using the Apartment gem, you can run the patches for each tenant in parallel.
53
45
  Just set the config ```sidekiq_parallel``` to ```true``` and you're good to go.
54
46
 
55
- ```
47
+ ```ruby
56
48
  Patches::Config.configure do |config|
57
49
  config.use_sidekiq = true
58
50
  config.sidekiq_parallel = true
@@ -62,6 +54,23 @@ end
62
54
  *Note:* Make sure your sidekiq queue is able to process concurrent jobs.
63
55
  You can use ```config.sidekiq_options``` to customise it.
64
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
+
65
74
  ## Creating Patches
66
75
 
67
76
  Generate a patch
@@ -84,7 +93,7 @@ update the run method and then execute
84
93
 
85
94
  Generate patch with specs
86
95
 
87
- ```
96
+ ```bash
88
97
  bundle exec rails g patches:patch PreferenceUpdate --specs=true
89
98
  ```
90
99
 
@@ -116,7 +125,7 @@ after sidekiq restarts, otherwise there is no guarentee the tasks will run.
116
125
  If a patch requires data assets, you could use S3 to store the file.
117
126
  If credentials are defined in env vars, as per https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#id1
118
127
 
119
- ```
128
+ ```ruby
120
129
  require 'aws-sdk-s3'
121
130
  Aws::S3::Client.new.get_object(bucket: @bucket_name, key: filename, response_target: destination)
122
131
  ```
@@ -22,6 +22,7 @@ end
22
22
  require "patches/base"
23
23
  require "patches/config"
24
24
  require "patches/tenant_run_concern"
25
+ require "patches/application_version_validation"
25
26
  require "patches/tenant_worker" if defined?(Sidekiq)
26
27
  require "patches/engine" if defined?(Rails)
27
28
  require "patches/patch"
@@ -0,0 +1,9 @@
1
+ module Patches
2
+ module ApplicationVersionValidation
3
+ def valid_application_version?(application_version)
4
+ return true unless application_version
5
+ return true unless Patches::Config.configuration.application_version
6
+ Patches::Config.configuration.application_version == application_version
7
+ end
8
+ end
9
+ end
@@ -14,8 +14,15 @@ module Patches
14
14
  end
15
15
 
16
16
  class Configuration
17
- attr_accessor :use_sidekiq, :sidekiq_queue, :sidekiq_options, :use_hipchat,
18
- :hipchat_options, :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,20 +32,8 @@ module Patches
25
32
  @sidekiq_options ||= { retry: false, queue: sidekiq_queue }
26
33
  end
27
34
 
28
- def hipchat_api_token
29
- hipchat_options[:api_token]
30
- end
31
-
32
- def hipchat_init_options
33
- hipchat_options.except(:api_token, :room, :user)
34
- end
35
-
36
- def hipchat_room
37
- hipchat_options[:room]
38
- end
39
-
40
- def hipchat_user
41
- hipchat_options[:user]
35
+ def retry_after_version_mismatch_in
36
+ @retry_after_version_mismatch_in ||= 1.minute
42
37
  end
43
38
 
44
39
  def slack_channel
@@ -3,12 +3,10 @@ require 'slack-notifier'
3
3
  class Patches::Notifier
4
4
  class << self
5
5
  def notify_success(patches)
6
- send_hipchat_message(success_message(patches), color: 'green')
7
6
  send_slack_message(success_message(patches), 'good')
8
7
  end
9
8
 
10
9
  def notify_failure(patch_path, error)
11
- send_hipchat_message(failure_message(patch_path, error), color: 'red')
12
10
  send_slack_message(failure_message(patch_path, error), 'danger')
13
11
  end
14
12
 
@@ -32,14 +30,6 @@ class Patches::Notifier
32
30
  message
33
31
  end
34
32
 
35
- def send_hipchat_message(message, options)
36
- return unless defined?(HipChat) && config.use_hipchat
37
-
38
- client = HipChat::Client.new(config.hipchat_api_token, config.hipchat_init_options)
39
- room = client[config.hipchat_room]
40
- room.send(config.hipchat_user, message, options)
41
- end
42
-
43
33
  def send_slack_message(message, color)
44
34
  return unless defined?(Slack) && config.use_slack
45
35
 
@@ -48,7 +38,7 @@ class Patches::Notifier
48
38
  channel: config.slack_channel,
49
39
  username: config.slack_username)
50
40
 
51
- payload = { attachments: [{ color: color, text: message }] }
41
+ payload = { icon_emoji: ":dog:", attachments: [{ color: color, text: message }] }
52
42
 
53
43
  notifier.post payload
54
44
  end
@@ -1,8 +1,9 @@
1
1
  module Patches
2
2
  module TenantRunConcern
3
3
  def run(tenant_name, path = nil)
4
- Apartment::Tenant.switch(tenant_name)
5
- Patches::Runner.new(path).perform
4
+ Apartment::Tenant.switch(tenant_name) do
5
+ Patches::Runner.new(path).perform
6
+ end
6
7
  end
7
8
  end
8
9
  end
@@ -11,7 +11,11 @@ class Patches::TenantRunner
11
11
  Patches.logger.info("Patches tenant runner for: #{tenants.join(',')}")
12
12
  tenants.each do |tenant|
13
13
  if parallel?
14
- Patches::TenantWorker.perform_async(tenant, path)
14
+ Patches::TenantWorker.perform_async(
15
+ tenant,
16
+ path,
17
+ application_version: Patches::Config.configuration.application_version
18
+ )
15
19
  else
16
20
  run(tenant, path)
17
21
  end
@@ -3,10 +3,15 @@ require 'sidekiq'
3
3
  class Patches::TenantWorker
4
4
  include Sidekiq::Worker
5
5
  include Patches::TenantRunConcern
6
+ include Patches::ApplicationVersionValidation
6
7
 
7
8
  sidekiq_options Patches::Config.configuration.sidekiq_options
8
9
 
9
- def perform(tenant_name, path)
10
- run(tenant_name, path)
10
+ def perform(tenant_name, path, params = {})
11
+ if valid_application_version?(params['application_version'])
12
+ run(tenant_name, path)
13
+ else
14
+ self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, tenant_name, path, params)
15
+ end
11
16
  end
12
17
  end
@@ -1,3 +1,6 @@
1
1
  module Patches
2
- VERSION = "2.4.1"
2
+ MAJOR = 3
3
+ MINOR = 5
4
+ PATCH = 0
5
+ VERSION = [MAJOR, MINOR, PATCH].compact.join(".").freeze
3
6
  end
@@ -2,10 +2,15 @@ require 'sidekiq'
2
2
 
3
3
  class Patches::Worker
4
4
  include Sidekiq::Worker
5
+ include Patches::ApplicationVersionValidation
5
6
 
6
7
  sidekiq_options Patches::Config.configuration.sidekiq_options
7
8
 
8
- def perform(runner)
9
- runner.constantize.new.perform
9
+ def perform(runner, params = {})
10
+ if valid_application_version?(params['application_version'])
11
+ runner.constantize.new.perform
12
+ else
13
+ self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, runner, params)
14
+ end
10
15
  end
11
16
  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"
@@ -34,7 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "database_cleaner", "~> 1.3.0"
35
35
  spec.add_development_dependency "pry"
36
36
  spec.add_development_dependency "sidekiq", "~> 3.4.1"
37
- spec.add_development_dependency "hipchat"
38
37
  spec.add_development_dependency "webmock"
39
38
  spec.add_development_dependency "byebug"
40
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patches
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JobReady
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-19 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -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
@@ -206,20 +206,6 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: 3.4.1
209
- - !ruby/object:Gem::Dependency
210
- name: hipchat
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
209
  - !ruby/object:Gem::Dependency
224
210
  name: webmock
225
211
  requirement: !ruby/object:Gem::Requirement
@@ -275,6 +261,7 @@ files:
275
261
  - lib/generators/patches/templates/patch.rb.erb
276
262
  - lib/generators/patches/templates/patch_spec.rb.erb
277
263
  - lib/patches.rb
264
+ - lib/patches/application_version_validation.rb
278
265
  - lib/patches/base.rb
279
266
  - lib/patches/capistrano.rb
280
267
  - lib/patches/capistrano/tasks.rake
@@ -291,7 +278,6 @@ files:
291
278
  - lib/patches/worker.rb
292
279
  - lib/tasks/patches.rake
293
280
  - patches.gemspec
294
- - script/buildkite.sh
295
281
  homepage: http://github.com/jobready/patches
296
282
  licenses:
297
283
  - MIT
@@ -311,8 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
297
  - !ruby/object:Gem::Version
312
298
  version: '0'
313
299
  requirements: []
314
- rubyforge_project:
315
- rubygems_version: 2.7.6
300
+ rubygems_version: 3.0.3
316
301
  signing_key:
317
302
  specification_version: 4
318
303
  summary: A simple gem for one off tasks
@@ -1,21 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- echo '--- setting ruby version'
5
- cd /var/lib/buildkite-agent/.rbenv/plugins/ruby-build && git pull && cd -
6
- rbenv install 2.3.7 -s
7
- rbenv local 2.3.7
8
-
9
- echo '--- setting up env'
10
- REVISION=https://github.com/$BUILDBOX_PROJECT_SLUG/commit/$BUILDBOX_COMMIT
11
-
12
- echo '--- bundling'
13
- bundle install -j $(nproc) --without production --quiet
14
-
15
- echo '--- running specs'
16
- if bundle exec rspec; then
17
- echo "[Successful] $BUILDBOX_PROJECT_SLUG - Build - $BUILDBOX_BUILD_URL - Commit - $REVISION" | hipchat_room_message -t $HIPCHAT_TOKEN -r $HIPCHAT_ROOM -f "Buildbox" -c "green"
18
- else
19
- echo "[Failed] Build $BUILDBOX_PROJECT_SLUG - Build - $BUILDBOX_BUILD_URL - Commit - $REVISION" | hipchat_room_message -t $HIPCHAT_TOKEN -r $HIPCHAT_ROOM -f "Buildbox" -c "red"
20
- exit 1;
21
- fi