Commit 28a19b15 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'helm_extraction_worker' into 'master'

Add Packages::Helm::ExtractionWorker

See merge request gitlab-org/gitlab!64281
parents 06280f89 8acef854
...@@ -1309,6 +1309,15 @@ ...@@ -1309,6 +1309,15 @@
:idempotent: true :idempotent: true
:tags: :tags:
- :exclude_from_kubernetes - :exclude_from_kubernetes
- :name: package_repositories:packages_helm_extraction
:worker_name: Packages::Helm::ExtractionWorker
:feature_category: :package_registry
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: package_repositories:packages_maven_metadata_sync - :name: package_repositories:packages_maven_metadata_sync
:worker_name: Packages::Maven::Metadata::SyncWorker :worker_name: Packages::Maven::Metadata::SyncWorker
:feature_category: :package_registry :feature_category: :package_registry
......
# frozen_string_literal: true
module Packages
module Helm
class ExtractionWorker
include ApplicationWorker
queue_namespace :package_repositories
feature_category :package_registry
deduplicate :until_executing
idempotent!
def perform(channel, package_file_id)
package_file = ::Packages::PackageFile.find_by_id(package_file_id)
return unless package_file && !package_file.package.default?
::Packages::Helm::ProcessFileService.new(channel, package_file).execute
rescue ::Packages::Helm::ExtractFileMetadataService::ExtractionError,
::Packages::Helm::ProcessFileService::ExtractionError,
::ActiveModel::ValidationError => e
Gitlab::ErrorTracking.log_exception(e, project_id: package_file.project_id)
package_file.package.update_column(:status, :error)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Helm::ExtractionWorker, type: :worker do
describe '#perform' do
let_it_be(:package) { create(:helm_package, without_package_files: true, status: 'processing')}
let!(:package_file) { create(:helm_package_file, without_loaded_metadatum: true, package: package) }
let(:package_file_id) { package_file.id }
let(:channel) { 'stable' }
let(:expected_metadata) do
{
'apiVersion' => 'v2',
'description' => 'File, Block, and Object Storage Services for your Cloud-Native Environment',
'icon' => 'https://rook.io/images/rook-logo.svg',
'name' => 'rook-ceph',
'sources' => ['https://github.com/rook/rook'],
'version' => 'v1.5.8'
}
end
subject { described_class.new.perform(channel, package_file_id) }
shared_examples 'handling error' do
it 'mark the package as errored', :aggregate_failures do
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
instance_of(Packages::Helm::ExtractFileMetadataService::ExtractionError),
project_id: package_file.package.project_id
)
expect { subject }
.to not_change { Packages::Package.count }
.and not_change { Packages::PackageFile.count }
.and change { package.reload.status }.from('processing').to('error')
end
end
context 'with valid package file' do
it_behaves_like 'an idempotent worker' do
let(:job_args) { [channel, package_file_id] }
it 'updates package and package file', :aggregate_failures do
expect(Gitlab::ErrorTracking).not_to receive(:log_exception)
expect { subject }
.to not_change { Packages::Package.count }
.and not_change { Packages::PackageFile.count }
.and change { Packages::Helm::FileMetadatum.count }.from(0).to(1)
.and change { package.reload.status }.from('processing').to('default')
helm_file_metadatum = package_file.helm_file_metadatum
expect(helm_file_metadatum.channel).to eq(channel)
expect(helm_file_metadatum.metadata).to eq(expected_metadata)
end
end
end
context 'with invalid package file id' do
let(:package_file_id) { 5555 }
it "doesn't update helm_file_metadatum", :aggregate_failures do
expect { subject }
.to not_change { Packages::Package.count }
.and not_change { Packages::PackageFile.count }
.and not_change { Packages::Helm::FileMetadatum.count }
.and not_change { package.reload.status }
end
end
context 'with an empty package file' do
before do
expect_next_instance_of(Gem::Package::TarReader) do |tar_reader|
expect(tar_reader).to receive(:each).and_return([])
end
end
it_behaves_like 'handling error'
end
context 'with an invalid YAML' do
before do
expect_next_instance_of(Gem::Package::TarReader::Entry) do |entry|
expect(entry).to receive(:read).and_return('{')
end
end
it_behaves_like 'handling error'
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment