Skip to content

Commit

Permalink
NEP-10148 TenantWorker forward compatibility with application version…
Browse files Browse the repository at this point in the history
… constraints (#27)
  • Loading branch information
andrba authored Jul 22, 2020
1 parent 0fc3b87 commit f20e018
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.4.0] - 2020-07-21
### Added
- `Patches::TenantWorker` application version constraint forward compatibility

## [3.3.0] - 2020-07-20
### Added
- Application version constraints
Expand Down
1 change: 1 addition & 0 deletions lib/patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def self.logger=(log)
require "patches/base"
require "patches/config"
require "patches/tenant_run_concern"
require "patches/application_version_validation"
require "patches/tenant_worker" if defined?(Sidekiq)
require "patches/engine" if defined?(Rails)
require "patches/patch"
Expand Down
9 changes: 9 additions & 0 deletions lib/patches/application_version_validation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Patches
module ApplicationVersionValidation
def valid_application_version?(application_version)
return true unless application_version
return true unless Patches::Config.configuration.application_version
Patches::Config.configuration.application_version == application_version
end
end
end
9 changes: 7 additions & 2 deletions lib/patches/tenant_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
class Patches::TenantWorker
include Sidekiq::Worker
include Patches::TenantRunConcern
include Patches::ApplicationVersionValidation

sidekiq_options Patches::Config.configuration.sidekiq_options

def perform(tenant_name, path)
run(tenant_name, path)
def perform(tenant_name, path, params = {})
if valid_application_version?(params['application_version'])
run(tenant_name, path)
else
self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, tenant_name, path, params)
end
end
end
2 changes: 1 addition & 1 deletion lib/patches/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Patches
MAJOR = 3
MINOR = 3
MINOR = 4
PATCH = 0
VERSION = [MAJOR, MINOR, PATCH].compact.join(".").freeze
end
11 changes: 2 additions & 9 deletions lib/patches/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

class Patches::Worker
include Sidekiq::Worker
include Patches::ApplicationVersionValidation

sidekiq_options Patches::Config.configuration.sidekiq_options

def perform(runner, params = {})
if valid_application_version?(params)
if valid_application_version?(params['application_version'])
runner.constantize.new.perform
else
self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, runner, params)
end
end

private

def valid_application_version?(params)
return true unless params['application_version']
return true unless Patches::Config.configuration.application_version
Patches::Config.configuration.application_version == params['application_version']
end
end
39 changes: 36 additions & 3 deletions spec/tenant_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@

describe Patches::TenantWorker do
describe '#perform' do
specify do
is_expected.to receive(:run).with('test', 'path')
subject.perform('test', 'path')
let(:runner) { instance_double(Patches::Runner, perform: true) }

before do
allow(Patches::Config.configuration).to receive(:application_version) { application_version }
end

context 'when application_version config is set' do
let(:application_version) { '5828321' }

context 'when application version matches' do
it 'runs patches' do
expect(subject).to receive(:run).with('test', 'path')
subject.perform('test', 'path', 'application_version' => application_version)
end
end

context 'when application_version does not match' do
it 'does not run patches' do
expect(subject).not_to receive(:run)
subject.perform('test', 'path', 'application_version' => 'd8f190c')
end

it 'reschedules the job' do
expect(Patches::TenantWorker).to receive(:perform_in).with(1.minute, 'test', 'path', 'application_version' => 'd8f190c')
subject.perform('test', 'path', 'application_version' => 'd8f190c')
end
end
end

context 'when application config is not set' do
let(:application_version) { nil }

it 'runs patches' do
expect(subject).to receive(:run).with('test', 'path')
subject.perform('test', 'path', 'application_version' => 'd8f190c')
end
end
end
end

0 comments on commit f20e018

Please sign in to comment.