patches 0.1.8 → 1.0.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
  SHA1:
3
- metadata.gz: 6b3d2cbeb7527f40447f40af14ba0e1f77f7e044
4
- data.tar.gz: 9bef2a16a778e769ef4aa95118e817ad0246283c
3
+ metadata.gz: 2aa4b0d46b34a6ec109a084e3fa4a98621227e11
4
+ data.tar.gz: d5addc26e43180c2946c7454fd48f0dfd80a86a8
5
5
  SHA512:
6
- metadata.gz: 3c7b3accf85699654b44802122b61a115357be010788810578e90693eae5acc8f623fbd997e1c003b33ccf1442d6a000e2286668703398dacce95884e432b002
7
- data.tar.gz: 613051dd3fb716f12b1f1d4957e91ccdbb8704ed2a40f6a3a5919e1ce6ed7f564de3245bb8730c2aea6b53330ed2cf24ed4e3a817891b276f9d86c4b70c1c813
6
+ metadata.gz: 644e49e78ac8b18a0cee626c83d4354092d90c0006df33aaa78001b1db497314ac09a71ab091a29fba4df11c50b1653f9a5bb2a8658b4eec834181660eb05cf6
7
+ data.tar.gz: e5ba79708cf10f043e2333b7197bb595d35e11f9428a7659dfa28312e78c260ecd8e5382980d26f3287da6e5420303b709e4a53961101fd660f3336d01f0eb75
data/README.md CHANGED
@@ -12,7 +12,6 @@ Add this line to your application's Gemfile:
12
12
  ```ruby
13
13
  gem 'patches'
14
14
  ```
15
-
16
15
  And then execute:
17
16
 
18
17
  $ bundle
@@ -33,8 +32,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
33
32
 
34
33
  ## Contributing
35
34
 
36
- 1. Fork it ( https://github.com/[my-github-username]/patches/fork )
37
- 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 1. Fork it ( https://github.com/jobready/patches/fork )
36
+ 2. Create your feature branch (`git checkout -b feature/my-feature-name`)
38
37
  3. Commit your changes (`git commit -am 'Add some feature'`)
39
- 4. Push to the branch (`git push origin my-new-feature`)
38
+ 4. Push to the branch (`git push origin feature/my-new-feature`)
40
39
  5. Create a new Pull Request
@@ -1,11 +1,42 @@
1
1
  # Usage
2
2
 
3
- Install the migration
3
+ ## Initial Setup
4
4
 
5
+ Add patches to the project Gemfile
6
+
7
+ ```ruby
8
+ gem 'patches', '~> 0.1'
5
9
  ```
10
+
11
+ Install the database migration
12
+
13
+ ```bash
6
14
  bundle exec rake patches:install:migrations
7
15
  ```
8
16
 
17
+ Migrate database
18
+
19
+ ```bash
20
+ bundle exec rake db:migrate
21
+ ```
22
+
23
+ If you would like to run the patches asynchronously, or would like them to notify your hipchat room when they fail or succeed, you need to set up an initializer to set those options.
24
+
25
+ ```Ruby
26
+ Patches::Config.configure do |config|
27
+ config.use_sidekiq = true
28
+
29
+ config.use_hipchat = true
30
+ config.hipchat_options = {
31
+ api_token: HIPCHATAPITOKEN,
32
+ room: HIPCHATROOMNAME,
33
+ user: HIPCHATUSER #maximum of 15 characters
34
+ }
35
+ end
36
+ ```
37
+
38
+ ## Creating Patches
39
+
9
40
  Generate a patch
10
41
 
11
42
  ```
@@ -29,10 +60,14 @@ update the run method and then execute
29
60
  bundle exec rake patches:run
30
61
  ```
31
62
 
32
- Patches will only ever run once, patches will run in order.
63
+ Patches will only ever run once, patches will run in order of creation date.
33
64
 
34
65
  To run patches after db:migrate on deployment edit Capfile and add
35
66
 
36
67
  ```ruby
37
68
  require 'patches/capistrano'
38
69
  ```
70
+
71
+ ## Multitenant
72
+
73
+ Patches will detect if `Apartment` gem is installed and if there are any tenants and run the patches for each tenant
@@ -24,3 +24,7 @@ require "patches/engine" if defined?(Rails)
24
24
  require "patches/patch"
25
25
  require "patches/pending"
26
26
  require "patches/runner"
27
+ require "patches/tenant_runner"
28
+ require "patches/config"
29
+ require "patches/notifier"
30
+ require "patches/worker" if defined?(Sidekiq)
@@ -0,0 +1,19 @@
1
+ module Patches
2
+ class Config
3
+ class << self
4
+ class_attribute :use_sidekiq, :sidekiq_queue, :sidekiq_options, :use_hipchat, :hipchat_options
5
+
6
+ def sidekiq_queue
7
+ @sidekiq_queue ||= 'default'
8
+ end
9
+
10
+ def sidekiq_options
11
+ @sidekiq_options ||= { retry: false, queue: Patches::Config.sidekiq_queue }
12
+ end
13
+
14
+ def configure
15
+ yield self
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ class Patches::Notifier
2
+ class << self
3
+ def notify_success(patches)
4
+ send_hipchat_message(success_message(patches), color: 'green')
5
+ end
6
+
7
+ def notify_failure(patch_path, error)
8
+ send_hipchat_message(failure_message(patch_path, error), color: 'red')
9
+ end
10
+
11
+ def success_message(patches)
12
+ message = "#{patches.count} patches succeeded"
13
+ append_tenant_message(message)
14
+ end
15
+
16
+ def failure_message(patch_path, error)
17
+ message = "Error applying patch: #{Pathname.new(patch_path).basename} failed with error: #{error}"
18
+ append_tenant_message(message)
19
+ end
20
+
21
+ def append_tenant_message(message)
22
+ message = message + " for tenant: #{Apartment::Tenant.current}" if defined?(Apartment)
23
+ message
24
+ end
25
+
26
+ private
27
+
28
+ def send_hipchat_message(message, options)
29
+ if defined?(HipChat) && Patches::Config.use_hipchat
30
+ HipChat::Client.new(Patches::Config.hipchat_options[:api_token])[Patches::Config.hipchat_options[:room]].send(Patches::Config.hipchat_options[:user], message, options)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -9,9 +9,10 @@ class Patches::Pending
9
9
 
10
10
  def each
11
11
  return nil unless files
12
- Patches.logger.info("Patches found: #{files.join(',')}")
12
+ new_files = files.reject { |file| already_run?(file) }
13
+ Patches.logger.info("Patches found: #{new_files.join(',')}")
13
14
 
14
- files.each do |file|
15
+ new_files.each do |file|
15
16
  unless already_run?(file)
16
17
  yield file
17
18
  end
@@ -8,13 +8,20 @@ class Patches::Runner
8
8
  end
9
9
 
10
10
  def perform
11
- pending.each do |file_path|
11
+ completed_patches = pending.each do |file_path|
12
12
  klass = load_class(file_path)
13
13
  instance = klass.new
14
14
  Patches.logger.info("Running #{klass} from #{file_path}")
15
- instance.run
15
+ begin
16
+ instance.run
17
+ rescue => e
18
+ Patches::Notifier.notify_failure(file_path, format_exception(e))
19
+ raise e
20
+ end
16
21
  complete!(patch_path(file_path))
17
22
  end
23
+ Patches::Notifier.notify_success(completed_patches)
24
+ completed_patches
18
25
  end
19
26
 
20
27
  def complete!(patch_path)
@@ -29,6 +36,10 @@ class Patches::Runner
29
36
  @pending ||= Patches::Pending.new(path)
30
37
  end
31
38
 
39
+ def format_exception(e)
40
+ "#{e.class.name}: #{e.message} (#{e.backtrace.first})"
41
+ end
42
+
32
43
  private
33
44
  def load_class(path)
34
45
  begin
@@ -1,3 +1,3 @@
1
1
  module Patches
2
- VERSION = "0.1.8"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'sidekiq'
2
+
3
+ class Patches::Worker
4
+ include Sidekiq::Worker
5
+
6
+ sidekiq_options Patches::Config.sidekiq_options
7
+
8
+ def perform(runner)
9
+ runner.constantize.new.perform
10
+ end
11
+ end
@@ -1,12 +1,16 @@
1
- require 'patches/tenant_runner'
2
-
3
1
  namespace :patches do
4
2
  desc "Run Patches"
5
3
  task :run => [:environment] do
6
4
  if defined?(Apartment) && tenants.present?
7
- Patches::TenantRunner.new(tenants: tenants).perform
5
+ runner = Patches::TenantRunner
6
+ else
7
+ runner = Patches::Runner
8
+ end
9
+
10
+ if defined?(Sidekiq) && Patches::Config.use_sidekiq
11
+ Patches::Worker.perform_async(runner)
8
12
  else
9
- Patches::Runner.new.perform
13
+ runner.new.perform
10
14
  end
11
15
  end
12
16
 
@@ -30,4 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "factory_girl", "~> 4.5.0"
31
31
  spec.add_development_dependency "timecop", "~> 0.7.0"
32
32
  spec.add_development_dependency "database_cleaner", "~> 1.3.0"
33
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "sidekiq", "~> 3.4.1"
33
36
  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: 0.1.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John D'Agostino
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -164,6 +164,48 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 1.3.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: codeclimate-test-reporter
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.4'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.4'
181
+ - !ruby/object:Gem::Dependency
182
+ name: pry
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sidekiq
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 3.4.1
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 3.4.1
167
209
  description: A simple gem for one of tasks for example database patches
168
210
  email:
169
211
  - johnd@jobready.com.au
@@ -188,12 +230,15 @@ files:
188
230
  - lib/patches/base.rb
189
231
  - lib/patches/capistrano.rb
190
232
  - lib/patches/capistrano/tasks.rake
233
+ - lib/patches/config.rb
191
234
  - lib/patches/engine.rb
235
+ - lib/patches/notifier.rb
192
236
  - lib/patches/patch.rb
193
237
  - lib/patches/pending.rb
194
238
  - lib/patches/runner.rb
195
239
  - lib/patches/tenant_runner.rb
196
240
  - lib/patches/version.rb
241
+ - lib/patches/worker.rb
197
242
  - lib/tasks/patches.rake
198
243
  - patches.gemspec
199
244
  - script/buildkite.sh
@@ -216,9 +261,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
261
  version: '0'
217
262
  requirements: []
218
263
  rubyforge_project:
219
- rubygems_version: 2.2.2
264
+ rubygems_version: 2.4.8
220
265
  signing_key:
221
266
  specification_version: 4
222
267
  summary: A simple gem for one off tasks
223
268
  test_files: []
224
- has_rdoc: