-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/gh-import-status-check' into 'master'
Periodically mark projects that are stuck in importing as failed Closes #17709 See merge request !10207
- Loading branch information
Showing
13 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,37 @@ | ||
class StuckImportJobsWorker | ||
include Sidekiq::Worker | ||
include CronjobQueue | ||
|
||
IMPORT_EXPIRATION = 15.hours.to_i | ||
|
||
def perform | ||
stuck_projects.find_in_batches(batch_size: 500) do |group| | ||
jids = group.map(&:import_jid) | ||
|
||
# Find the jobs that aren't currently running or that exceeded the threshold. | ||
completed_jids = Gitlab::SidekiqStatus.completed_jids(jids) | ||
|
||
if completed_jids.any? | ||
completed_ids = group.select { |project| completed_jids.include?(project.import_jid) }.map(&:id) | ||
|
||
fail_batch!(completed_jids, completed_ids) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def stuck_projects | ||
Project.select('id, import_jid').with_import_status(:started).where.not(import_jid: nil) | ||
end | ||
|
||
def fail_batch!(completed_jids, completed_ids) | ||
Project.where(id: completed_ids).update_all(import_status: 'failed', import_error: error_message) | ||
|
||
Rails.logger.info("Marked stuck import jobs as failed. JIDs: #{completed_jids.join(', ')}") | ||
end | ||
|
||
def error_message | ||
"Import timed out. Import took longer than #{IMPORT_EXPIRATION} seconds" | ||
end | ||
end |
This file contains 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,4 @@ | ||
--- | ||
title: Periodically mark projects that are stuck in importing as failed | ||
merge_request: | ||
author: |
This file contains 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 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 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,9 @@ | ||
class AddImportJidToProjects < ActiveRecord::Migration | ||
include Gitlab::Database::MigrationHelpers | ||
|
||
DOWNTIME = false | ||
|
||
def change | ||
add_column :projects, :import_jid, :string | ||
end | ||
end |
This file contains 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 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 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 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 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 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 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,36 @@ | ||
require 'spec_helper' | ||
|
||
describe StuckImportJobsWorker do | ||
let(:worker) { described_class.new } | ||
let(:exclusive_lease_uuid) { SecureRandom.uuid } | ||
|
||
before do | ||
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(exclusive_lease_uuid) | ||
end | ||
|
||
describe 'long running import' do | ||
let(:project) { create(:empty_project, import_jid: '123', import_status: 'started') } | ||
|
||
before do | ||
allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return(['123']) | ||
end | ||
|
||
it 'marks the project as failed' do | ||
expect { worker.perform }.to change { project.reload.import_status }.to('failed') | ||
end | ||
end | ||
|
||
describe 'running import' do | ||
let(:project) { create(:empty_project, import_jid: '123', import_status: 'started') } | ||
|
||
before do | ||
allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([]) | ||
end | ||
|
||
it 'does not mark the project as failed' do | ||
worker.perform | ||
|
||
expect(project.reload.import_status).to eq('started') | ||
end | ||
end | ||
end |