Commit c4cb8a8f authored by David Kim's avatar David Kim

Merge branch 'kassio/bulkimports-error-handling-and-log-for-after-run' into 'master'

BulkImports: Better error handling and logging for `Pipeline#after_run`

See merge request gitlab-org/gitlab!54139
parents a98fec6d c7cb0ae8
......@@ -26,7 +26,11 @@ module BulkImports
end
end
after_run(extracted_data) if respond_to?(:after_run)
if respond_to?(:after_run)
run_pipeline_step(:after_run) do
after_run(extracted_data)
end
end
info(message: 'Pipeline finished')
rescue MarkedAsFailedError
......@@ -35,7 +39,7 @@ module BulkImports
private # rubocop:disable Lint/UselessAccessModifier
def run_pipeline_step(step, class_name)
def run_pipeline_step(step, class_name = nil)
raise MarkedAsFailedError if marked_as_failed?
info(pipeline_step: step, step_class: class_name)
......@@ -92,19 +96,21 @@ module BulkImports
end
def warn(extra = {})
logger.warn(log_base_params.merge(extra))
logger.warn(log_params(extra))
end
def info(extra = {})
logger.info(log_base_params.merge(extra))
logger.info(log_params(extra))
end
def log_base_params
{
def log_params(extra)
defaults = {
bulk_import_entity_id: context.entity.id,
bulk_import_entity_type: context.entity.source_type,
pipeline_class: pipeline
}
defaults.merge(extra).compact
end
def logger
......
......@@ -39,6 +39,8 @@ RSpec.describe BulkImports::Pipeline::Runner do
extractor BulkImports::Extractor
transformer BulkImports::Transformer
loader BulkImports::Loader
def after_run(_); end
end
stub_const('BulkImports::MyPipeline', pipeline)
......@@ -103,6 +105,13 @@ RSpec.describe BulkImports::Pipeline::Runner do
pipeline_step: :loader,
step_class: 'BulkImports::Loader'
)
expect(logger).to receive(:info)
.with(
bulk_import_entity_id: entity.id,
bulk_import_entity_type: 'group_entity',
pipeline_class: 'BulkImports::MyPipeline',
pipeline_step: :after_run
)
expect(logger).to receive(:info)
.with(
bulk_import_entity_id: entity.id,
......
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