Commit c71eaa56 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'make-import-issues-csv-worker-idempotent' into 'master'

Make ImportIssuesCsvWorker idempotent

See merge request gitlab-org/gitlab!47808
parents fa37bef6 9adb90fa
...@@ -1609,7 +1609,7 @@ ...@@ -1609,7 +1609,7 @@
:urgency: :low :urgency: :low
:resource_boundary: :cpu :resource_boundary: :cpu
:weight: 2 :weight: 2
:idempotent: :idempotent: true
:tags: [] :tags: []
- :name: invalid_gpg_signature_update - :name: invalid_gpg_signature_update
:feature_category: :source_code_management :feature_category: :source_code_management
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class ImportIssuesCsvWorker # rubocop:disable Scalability/IdempotentWorker class ImportIssuesCsvWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker include ApplicationWorker
idempotent!
feature_category :issue_tracking feature_category :issue_tracking
worker_resource_boundary :cpu worker_resource_boundary :cpu
weight 2 weight 2
...@@ -12,13 +13,15 @@ class ImportIssuesCsvWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -12,13 +13,15 @@ class ImportIssuesCsvWorker # rubocop:disable Scalability/IdempotentWorker
end end
def perform(current_user_id, project_id, upload_id) def perform(current_user_id, project_id, upload_id)
@user = User.find(current_user_id) user = User.find(current_user_id)
@project = Project.find(project_id) project = Project.find(project_id)
@upload = Upload.find(upload_id) upload = Upload.find(upload_id)
importer = Issues::ImportCsvService.new(@user, @project, @upload.retrieve_uploader) importer = Issues::ImportCsvService.new(user, project, upload.retrieve_uploader)
importer.execute importer.execute
@upload.destroy upload.destroy
rescue ActiveRecord::RecordNotFound
# Resources have been removed, job should not be retried
end end
end end
---
title: Make ImportIssuesCsvWorker idempotent
merge_request: 47808
author:
type: changed
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ImportIssuesCsvWorker do RSpec.describe ImportIssuesCsvWorker do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:upload) { create(:upload) } let(:upload) { create(:upload, :with_file) }
let(:worker) { described_class.new } let(:worker) { described_class.new }
...@@ -19,5 +19,9 @@ RSpec.describe ImportIssuesCsvWorker do ...@@ -19,5 +19,9 @@ RSpec.describe ImportIssuesCsvWorker do
expect { upload.reload }.to raise_error ActiveRecord::RecordNotFound expect { upload.reload }.to raise_error ActiveRecord::RecordNotFound
end end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [user.id, project.id, upload.id] }
end
end 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