-
Notifications
You must be signed in to change notification settings - Fork 0
Check primary runtime conflicts #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class UpdateRuntimeCompatibilityJob < ApplicationJob | ||
| def perform(conditions) | ||
| assignments = NamespaceProjectRuntimeAssignment.where(conditions) | ||
|
|
||
| assignments.each do |assignment| | ||
| res = Runtimes::CheckRuntimeCompatibilityService.new(assignment.runtime, assignment.namespace_project).execute | ||
|
|
||
| assignment.compatible = res.success? | ||
| assignment.save! | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/services/runtimes/check_runtime_compatibility_service.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Runtimes | ||
| class CheckRuntimeCompatibilityService | ||
| attr_reader :runtime, :namespace_project | ||
|
|
||
| def initialize(runtime, namespace_project) | ||
| @runtime = runtime | ||
| @namespace_project = namespace_project | ||
| end | ||
|
|
||
| def execute | ||
| primary_runtime = namespace_project.primary_runtime | ||
|
|
||
| if primary_runtime.nil? | ||
| return ServiceResponse.error(message: 'No primary runtime given', | ||
| error_code: :missing_primary_runtime) | ||
| end | ||
|
|
||
| { DataType => :identifier, FlowType => :identifier, | ||
| RuntimeFunctionDefinition => :runtime_name }.each do |model, identifier_field| | ||
| res = check_versions(model, identifier_field) | ||
| return res if res.error? | ||
| end | ||
| ServiceResponse.success(message: 'Runtime is compatible', payload: runtime) | ||
| end | ||
|
|
||
| def check_versions(model, identifier_field = :identifier) | ||
| to_check_types = model.where(runtime: runtime) | ||
| primary_types = model.where(runtime: namespace_project.primary_runtime) | ||
|
|
||
| if to_check_types.size < primary_types.size | ||
| return ServiceResponse.error(message: "#{model} amount dont match", | ||
| error_code: :missing_definition) | ||
| end | ||
|
|
||
| primary_types.each do |curr_type| | ||
| to_check = model.find_by(runtime: runtime, identifier_field => curr_type.send(identifier_field)) | ||
Knerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if to_check.nil? | ||
| return ServiceResponse.error(message: "#{model} is not present in new runtime", | ||
| error_code: :missing_definition) | ||
| end | ||
|
|
||
Knerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result = compare_version(curr_type.parsed_version, to_check.parsed_version) | ||
|
|
||
| unless result | ||
| return ServiceResponse.error(message: "#{model} is outdated", | ||
| error_code: :outdated_definition) | ||
| end | ||
| end | ||
| ServiceResponse.success | ||
| end | ||
|
|
||
| # true: compatible | ||
| # false: not compatible | ||
| def compare_version(primary_version, to_check_version) | ||
| return false if primary_version.segments[0] != to_check_version.segments[0] | ||
| return false if primary_version.segments[1] > to_check_version.segments[1] | ||
|
|
||
| true | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
db/migrate/20251109141754_add_is_compatible_to_primary_runtime.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddIsCompatibleToPrimaryRuntime < Code0::ZeroTrack::Database::Migration[1.0] | ||
| def change | ||
| add_column :namespace_project_runtime_assignments, :compatible, :boolean, null: false, default: false | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| d8a8171eddb13a575d76518ba6092f9f96d3b1e238d04da86104efc117ffbf14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe UpdateRuntimeCompatibilityJob do | ||
| include ActiveJob::TestHelper | ||
|
|
||
| it 'calls the compatibility service for each assignment and updates compatible' do | ||
| assignment1 = create(:namespace_project_runtime_assignment, compatible: false) | ||
| assignment2 = create(:namespace_project_runtime_assignment, compatible: false) | ||
|
|
||
| success_res = ServiceResponse.success | ||
| err_response = ServiceResponse.error(error_code: :outdated_definition, message: 'Runtime is outdated') | ||
|
|
||
| service1 = instance_double(Runtimes::CheckRuntimeCompatibilityService, execute: success_res) | ||
| service2 = instance_double(Runtimes::CheckRuntimeCompatibilityService, execute: err_response) | ||
|
|
||
| allow(Runtimes::CheckRuntimeCompatibilityService).to receive(:new) | ||
| .with(assignment1.runtime, assignment1.namespace_project).and_return(service1) | ||
| allow(Runtimes::CheckRuntimeCompatibilityService).to receive(:new) | ||
| .with(assignment2.runtime, assignment2.namespace_project).and_return(service2) | ||
|
|
||
| conditions = { id: [assignment1.id, assignment2.id] } | ||
|
|
||
| perform_enqueued_jobs do | ||
| described_class.perform_later(conditions) | ||
| end | ||
|
|
||
| expect(assignment1.reload.compatible).to be true | ||
| expect(assignment2.reload.compatible).to be false | ||
| end | ||
| end |
61 changes: 61 additions & 0 deletions
61
spec/services/runtimes/check_runtime_compatibility_service_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Runtimes::CheckRuntimeCompatibilityService do | ||
| subject(:service_response) do | ||
| described_class.new(runtime, project).execute | ||
| end | ||
|
|
||
| let(:primary_runtime) { create(:runtime) } | ||
| let(:runtime) { create(:runtime) } | ||
| let(:project) { create(:namespace_project, primary_runtime: primary_runtime) } | ||
|
|
||
| context 'when primary runtime is missing' do | ||
| let(:project) { create(:namespace_project) } | ||
|
|
||
| it 'returns an error with :missing_primary_runtime payload' do | ||
| expect(service_response).to be_error | ||
| expect(service_response.payload[:error_code]).to eq(:missing_primary_runtime) | ||
| end | ||
| end | ||
|
|
||
| context 'when a model has fewer types on the runtime than on the primary' do | ||
| before do | ||
| create(:data_type, runtime: primary_runtime) | ||
| end | ||
|
|
||
| it 'returns missing_datatypes error' do | ||
| expect(service_response.error?).to be true | ||
| expect(service_response.payload[:error_code]).to eq(:missing_definition) | ||
| end | ||
| end | ||
|
|
||
| context 'when secondary runtime has outdated definitions' do | ||
| before do | ||
| create(:data_type, runtime: primary_runtime, identifier: 'dt1', version: '1.3.0') | ||
| create(:data_type, runtime: runtime, identifier: 'dt1', version: '1.2.0') | ||
| end | ||
|
|
||
| it 'returns outdated_data_type error' do | ||
| expect(service_response.error?).to be true | ||
| expect(service_response.payload[:error_code]).to eq(:outdated_definition) | ||
| end | ||
| end | ||
|
|
||
| context 'when all models are compatible' do | ||
| before do | ||
| create(:data_type, runtime: primary_runtime, identifier: 'dt1', version: '1.3.0') | ||
| create(:data_type, runtime: runtime, identifier: 'dt1', version: '1.3.0') | ||
| create(:flow_type, runtime: primary_runtime, identifier: 'ft1', version: '2.1.0') | ||
| create(:flow_type, runtime: runtime, identifier: 'ft1', version: '2.2.0') | ||
| create(:runtime_function_definition, runtime_name: 'rfd1', runtime: primary_runtime, version: '3.0.0') | ||
| create(:runtime_function_definition, runtime_name: 'rfd1', runtime: runtime, version: '3.1.0') | ||
| end | ||
|
|
||
| it 'returns success with the runtime as payload' do | ||
| expect(service_response).to be_success | ||
| expect(service_response.payload).to eq(runtime) | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.