Commit e610f960 authored by Tiago Botelho's avatar Tiago Botelho Committed by Douwe Maan

Adds scheduled import jobs to the stuck import jobs detection worker.

parent 58a312f5
...@@ -16,7 +16,7 @@ class StuckImportJobsWorker ...@@ -16,7 +16,7 @@ class StuckImportJobsWorker
private private
def mark_projects_without_jid_as_failed! def mark_projects_without_jid_as_failed!
started_projects_without_jid.each do |project| enqueued_projects_without_jid.each do |project|
project.mark_import_as_failed(error_message) project.mark_import_as_failed(error_message)
end.count end.count
end end
...@@ -24,7 +24,7 @@ class StuckImportJobsWorker ...@@ -24,7 +24,7 @@ class StuckImportJobsWorker
def mark_projects_with_jid_as_failed! def mark_projects_with_jid_as_failed!
completed_jids_count = 0 completed_jids_count = 0
started_projects_with_jid.find_in_batches(batch_size: 500) do |group| enqueued_projects_with_jid.find_in_batches(batch_size: 500) do |group|
jids = group.map(&:import_jid) jids = group.map(&:import_jid)
# Find the jobs that aren't currently running or that exceeded the threshold. # Find the jobs that aren't currently running or that exceeded the threshold.
...@@ -43,16 +43,16 @@ class StuckImportJobsWorker ...@@ -43,16 +43,16 @@ class StuckImportJobsWorker
completed_jids_count completed_jids_count
end end
def started_projects def enqueued_projects
Project.with_import_status(:started) Project.with_import_status(:scheduled, :started)
end end
def started_projects_with_jid def enqueued_projects_with_jid
started_projects.where.not(import_jid: nil) enqueued_projects.where.not(import_jid: nil)
end end
def started_projects_without_jid def enqueued_projects_without_jid
started_projects.where(import_jid: nil) enqueued_projects.where(import_jid: nil)
end end
def error_message def error_message
......
---
title: Find stuck scheduled import jobs and also mark them as failed.
merge_request: 3055
author:
type: fixed
...@@ -8,9 +8,7 @@ describe StuckImportJobsWorker do ...@@ -8,9 +8,7 @@ describe StuckImportJobsWorker do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(exclusive_lease_uuid) allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(exclusive_lease_uuid)
end end
describe 'with started import_status' do shared_examples 'project import job detection' do
let(:project) { create(:project, :import_started, import_jid: '123') }
describe 'long running import' do describe 'long running import' do
it 'marks the project as failed' do it 'marks the project as failed' do
allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return(['123']) allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return(['123'])
...@@ -33,4 +31,16 @@ describe StuckImportJobsWorker do ...@@ -33,4 +31,16 @@ describe StuckImportJobsWorker do
end end
end end
end end
describe 'with scheduled import_status' do
it_behaves_like 'project import job detection' do
let(:project) { create(:project, :import_scheduled, import_jid: '123') }
end
end
describe 'with started import_status' do
it_behaves_like 'project import job detection' do
let(:project) { create(:project, :import_started, import_jid: '123') }
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