Commit c7cb0ae8 authored by Kassio Borges's avatar Kassio Borges

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

Run `Pipeline#after_run` like any other pipeline stpe to have the same
error handling and logging behavior.
parent dda09a0c
......@@ -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