Skip to content
代码片段 群组 项目
未验证 提交 6c87ca98 编辑于 作者: Luke Duncalfe's avatar Luke Duncalfe 提交者: GitLab
浏览文件

Merge branch...

Merge branch '512525-fix-user-contributions-export-worker-can-re-enqueue-itself-forever' into 'master' 

fix UserContributionsExportWorker to stop re-enqueue itself forever

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/183645



Merged-by: default avatarLuke Duncalfe <lduncalfe@gitlab.com>
Approved-by: default avatarLuke Duncalfe <lduncalfe@gitlab.com>
Reviewed-by: default avatarLuke Duncalfe <lduncalfe@gitlab.com>
Reviewed-by: default avatarSam Word <sword@gitlab.com>
Co-authored-by: default avatarImjaydip <jpansuriya@gitlab.com>
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module BulkImports module BulkImports
class UserContributionsExportWorker class UserContributionsExportWorker
include ApplicationWorker include ApplicationWorker
include Gitlab::Utils::StrongMemoize
idempotent! idempotent!
data_consistency :sticky data_consistency :sticky
...@@ -31,6 +32,7 @@ def perform(portable_id, portable_class, user_id, enqueued_at = nil) ...@@ -31,6 +32,7 @@ def perform(portable_id, portable_class, user_id, enqueued_at = nil)
def no_exports? def no_exports?
portable.bulk_import_exports.empty? portable.bulk_import_exports.empty?
end end
strong_memoize_attr :no_exports?
def job_stuck_without_exports? def job_stuck_without_exports?
has_been_enqueued_longer_limit = enqueued_at < EXPORT_TIMEOUT.ago has_been_enqueued_longer_limit = enqueued_at < EXPORT_TIMEOUT.ago
...@@ -38,9 +40,18 @@ def job_stuck_without_exports? ...@@ -38,9 +40,18 @@ def job_stuck_without_exports?
end end
def exports_still_processing? def exports_still_processing?
# The earlier check '#job_stuck_without_exports?' means the export has not hung with no exports at this point
return true if no_exports?
started_exports = portable.bulk_import_exports.for_status(BulkImports::Export::STARTED) started_exports = portable.bulk_import_exports.for_status(BulkImports::Export::STARTED)
started_exports.any?(&:relation_has_user_contributions?) || no_exports? started_exports.any? do |export|
# Skip over exports that would never have user contributions to export
next unless export.relation_has_user_contributions?
# Check that export isn't stale
export.updated_at > EXPORT_TIMEOUT.ago
end
end end
def re_enqueue def re_enqueue
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
let(:job_args) { [project.id, project.class.name, user.id] } let(:job_args) { [project.id, project.class.name, user.id] }
let(:current_time) { Time.current } let(:current_time) { Time.current }
let_it_be(:stale_export_timeout) { 7.hours.ago }
describe '#perform' do describe '#perform' do
it_behaves_like 'an idempotent worker' do it_behaves_like 'an idempotent worker' do
...@@ -92,6 +93,14 @@ ...@@ -92,6 +93,14 @@
end end
it_behaves_like 'user contributions are still being cached during export' it_behaves_like 'user contributions are still being cached during export'
context 'if the export is stuck in started state' do
before do
merge_requests_export.update!(updated_at: stale_export_timeout)
end
it_behaves_like 'user contributions export is started'
end
end end
context 'when an export not relating to users is still incomplete' do context 'when an export not relating to users is still incomplete' do
...@@ -100,11 +109,30 @@ ...@@ -100,11 +109,30 @@
it_behaves_like 'user contributions export is started' it_behaves_like 'user contributions export is started'
end end
context 'when some exports relating to users and some not relating to users are still incomplete' do context 'when both user-related and non-user-related exports exist with different statuses' do
let!(:issues_export) { create(:bulk_import_export, :started, project: project, relation: 'issues') } let!(:issues_export) { create(:bulk_import_export, :started, project: project, relation: 'issues') }
let!(:labels_export) { create(:bulk_import_export, :started, project: project, relation: 'labels') } let!(:labels_export) { create(:bulk_import_export, :started, project: project, relation: 'labels') }
it_behaves_like 'user contributions are still being cached during export' it_behaves_like 'user contributions are still being cached during export'
context 'when user-related exports are stale (older than timeout limit)' do
before do
issues_export.update!(updated_at: stale_export_timeout)
end
it_behaves_like 'user contributions export is started'
end
context 'when user-related exports are still active (not stale)' do
before do
# Make non-user exports stale, but this shouldn't affect the decision
labels_export.update!(updated_at: stale_export_timeout)
end
# Even though non-user-related exports are stale, the worker should still cache contributions
# because user-related exports are still active
it_behaves_like 'user contributions are still being cached during export'
end
end end
context 'when no exports have been created yet' do context 'when no exports have been created yet' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册