public override IEtlOperationResult Execute(EtlPipelineContext context)
        {
            var log = context.GetLogger(GetType().Name);

            if (!_predicate(context))
            {
                log.Info($"Predicate evaluated to false for running of '{Name}', skipping.");
                return(new EtlOperationResult(true));
            }

            log.Info($"Predicate evaluated to true for running of '{Name}', executing.");
            return(_operation.Execute(context));
        }
Exemple #2
0
        private IEtlOperationResult ExecuteOperation(IEtlOperation operation, EtlPipelineContext context)
        {
            _currentlyExecutingOperation = operation;

            IEtlOperationResult result = null;

            try
            {
                switch (operation)
                {
                case IConditionalLoopEtlOperation loop:
                {
                    var multiResult = new EtlOperationResult(true);
                    do
                    {
                        foreach (var op in loop.GetOperations())
                        {
                            _executionResults[op] = LastResult = ExecuteOperation(op, context);
                            multiResult
                            .WithErrors(LastResult.Errors)
                            .QuiesceSuccess(LastResult.IsSuccess);
                        }
                    } while (loop.Predicate(Context));
                    return(multiResult);
                }

                case IEtlOperationCollection collection:
                {
                    var multiResult = new EtlOperationResult(true);
                    foreach (var op in collection.GetOperations())
                    {
                        _executionResults[op] = LastResult = ExecuteOperation(op, context);
                        multiResult
                        .WithErrors(LastResult.Errors)
                        .QuiesceSuccess(LastResult.IsSuccess);
                    }

                    return(multiResult);
                }

                default:
                    result = operation.Execute(context);
                    break;
                }
            }
            catch (Exception e)
            {
                if (EtlLibConfig.EnableDebug)
                {
                    Debugger.Break();
                }

                _log.Error(
                    $"An error occured while executing operation '{operation.Name}' ({operation.GetType().Name}): {e}");
                var error = new EtlOperationError(operation, e);
                if (!_settings.OnErrorFn.Invoke(context, new[] { error }))
                {
                    throw new PipelineAbortException(operation, error);
                }
            }
            finally
            {
                if (result?.Errors.Count > 0)
                {
                    context.ReportErrors(result.Errors);
                    if (!_settings.OnErrorFn.Invoke(context, result.Errors.ToArray()))
                    {
                        throw new PipelineAbortException(operation, result.Errors);
                    }
                }

                if (operation is IDisposable disposable)
                {
                    _log.Debug("Disposing of resources used by step.");
                    disposable.Dispose();
                }

                _log.Debug("Cleaning up (globally).");
                GC.Collect();
            }

            return(result);
        }