Commit 707ab6ed authored by Eugenia Grieff's avatar Eugenia Grieff Committed by Bob Van Landuyt

Add worker for import csv requirements

- Add job to queues
- Add specs
parent 0a4a6591
......@@ -288,6 +288,8 @@
- 1
- - repository_update_remote_mirror
- 1
- - requirements_management_import_requirements_csv
- 1
- - requirements_management_process_requirements_reports
- 1
- - security_scans
......
......@@ -741,6 +741,14 @@
:weight: 1
:idempotent:
:tags: []
- :name: requirements_management_import_requirements_csv
:feature_category: :requirements_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: requirements_management_process_requirements_reports
:feature_category: :requirements_management
:has_external_dependencies:
......
# frozen_string_literal: true
module RequirementsManagement
class ImportRequirementsCsvWorker
include ApplicationWorker
include Gitlab::Utils::StrongMemoize
idempotent!
feature_category :requirements_management
# TODO: Set worker_resource_boundary.
# https://gitlab.com/gitlab-org/gitlab/-/issues/281173
sidekiq_retries_exhausted do |job|
Upload.find(job['args'][2]).destroy
end
def perform(current_user_id, project_id, upload_id)
upload = Upload.find(upload_id)
user = User.find(current_user_id)
project = Project.find(project_id)
RequirementsManagement::ImportCsvService.new(user, project, upload.retrieve_uploader).execute
upload.destroy!
rescue ActiveRecord::RecordNotFound
# Resources have been removed, job should not be retried
end
end
end
---
title: Add Sidekiq job for importing csv requirements async
merge_request: 46429
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RequirementsManagement::ImportRequirementsCsvWorker do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:upload) { create(:upload, :with_file) }
subject { described_class.new.perform(user.id, project.id, upload.id) }
describe '#perform' do
it 'calls #execute on Requirements::ImportCsvService and destroys upload' do
expect_next_instance_of(RequirementsManagement::ImportCsvService) do |instance|
expect(instance).to receive(:execute).and_return({ success: 5, error_lines: [], parse_error: false })
end
subject
expect { upload.reload }.to raise_error ActiveRecord::RecordNotFound
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [user.id, project.id, upload.id] }
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