Commit 0c8948dd authored by Kassio Borges's avatar Kassio Borges

Enable BulkImports::PipelineWorker to re-run started trackers

parent 337e2845
...@@ -50,6 +50,8 @@ class BulkImports::Tracker < ApplicationRecord ...@@ -50,6 +50,8 @@ class BulkImports::Tracker < ApplicationRecord
event :start do event :start do
transition created: :started transition created: :started
# To avoid errors when re-starting a pipeline in case of network errors
transition started: :started
end end
event :finish do event :finish do
......
...@@ -16,7 +16,7 @@ module BulkImports ...@@ -16,7 +16,7 @@ module BulkImports
def perform(pipeline_tracker_id, stage, entity_id) def perform(pipeline_tracker_id, stage, entity_id)
pipeline_tracker = ::BulkImports::Tracker pipeline_tracker = ::BulkImports::Tracker
.with_status(:created) .with_status(:created, :started)
.find_by_id(pipeline_tracker_id) .find_by_id(pipeline_tracker_id)
if pipeline_tracker.present? if pipeline_tracker.present?
......
...@@ -27,13 +27,8 @@ RSpec.describe BulkImports::PipelineWorker do ...@@ -27,13 +27,8 @@ RSpec.describe BulkImports::PipelineWorker do
.and_return([[0, pipeline_class]]) .and_return([[0, pipeline_class]])
end end
shared_examples 'successfully runs the pipeline' do
it 'runs the given pipeline successfully' do it 'runs the given pipeline successfully' do
pipeline_tracker = create(
:bulk_import_tracker,
entity: entity,
pipeline_name: 'FakePipeline'
)
expect_next_instance_of(Gitlab::Import::Logger) do |logger| expect_next_instance_of(Gitlab::Import::Logger) do |logger|
expect(logger) expect(logger)
.to receive(:info) .to receive(:info)
...@@ -57,12 +52,34 @@ RSpec.describe BulkImports::PipelineWorker do ...@@ -57,12 +52,34 @@ RSpec.describe BulkImports::PipelineWorker do
expect(pipeline_tracker.status_name).to eq(:finished) expect(pipeline_tracker.status_name).to eq(:finished)
expect(pipeline_tracker.jid).to eq('jid') expect(pipeline_tracker.jid).to eq('jid')
end end
end
it_behaves_like 'successfully runs the pipeline' do
let(:pipeline_tracker) do
create(
:bulk_import_tracker,
entity: entity,
pipeline_name: 'FakePipeline'
)
end
end
it_behaves_like 'successfully runs the pipeline' do
let(:pipeline_tracker) do
create(
:bulk_import_tracker,
:started,
entity: entity,
pipeline_name: 'FakePipeline'
)
end
end
context 'when the pipeline cannot be found' do context 'when the pipeline cannot be found' do
it 'logs the error' do it 'logs the error' do
pipeline_tracker = create( pipeline_tracker = create(
:bulk_import_tracker, :bulk_import_tracker,
:started, :finished,
entity: entity, entity: entity,
pipeline_name: 'FakePipeline' pipeline_name: 'FakePipeline'
) )
......
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