Ejemplo n.º 1
0
        public void MarkEnded(PipelineContext ctx)
        {
            ElapsedSeconds = (int)(DateTime.UtcNow - utcStart).TotalSeconds;
            Added          = ctx.Added;
            Deleted        = ctx.Deleted;
            Emitted        = ctx.Emitted;
            Errors         = ctx.Errors;
            Skipped        = ctx.Skipped;
            ErrorMessage   = ctx.LastError == null ? null : ctx.LastError.Message;

            StringBuilder sb = new StringBuilder();

            sb.Append("Elapsed=");
            sb.Append(Pretty.PrintElapsed(ElapsedSeconds));
            sb.Append(", ");
            sb.Append(ctx.GetStats());
            Stats = sb.ToString();

            ErrorState = ctx.ErrorState == _ErrorState.Running ? _ErrorState.OK : ctx.ErrorState;
        }
Ejemplo n.º 2
0
        public void Import(PipelineContext ctx)
        {
            Logger importLog  = ctx.ImportLog;
            Logger errorLog   = ctx.ErrorLog;
            bool   stopNeeded = false;

            importLog.Log(_LogType.ltProgress | _LogType.ltTimerStart, "[{0}]: starting import with pipeline {1}, default endpoint={2}, maxadds={3} ", Name, Pipeline.Name, Pipeline.DefaultEndpoint, ctx.MaxAdds);

            Pipeline.Start(ctx);
            Pipeline.HandleValue(ctx, "_datasource/_start", this);
            try
            {
                Datasource.Import(ctx, Pipeline);
                importLog.Log(_LogType.ltProgress | _LogType.ltTimerStop, "[{0}]: raw import ended. Partial stats={1}.", Name, ctx.GetStats());
                stopNeeded = true;
            }

            catch (Exception e)
            {
                ctx.LastError = e;
                if (MaxAddsExceededException.ContainsMaxAddsExceededException(e))
                {
                    stopNeeded      = true;
                    ctx.ErrorState |= _ErrorState.Limited;
                    importLog.Log(_LogType.ltWarning | _LogType.ltTimerStop, "[{0}]: {1}", Name, e.Message);
                    importLog.Log("-- " + ctx.GetStats());
                    if ((ctx.ImportFlags & _ImportFlags.IgnoreLimited) != 0)
                    {
                        importLog.Log(_LogType.ltWarning, "Limited ignored due to importFlags [{0}].", ctx.ImportFlags);
                    }
                    stopNeeded = true;
                }
                else
                {
                    ctx.ErrorState |= _ErrorState.Error;
                    String msg = String.Format("[{0}]: crashed err={1}", Name, e.Message);
                    importLog.Log(_LogType.ltError | _LogType.ltTimerStop, msg);
                    importLog.Log("-- " + ctx.GetStats());
                    errorLog.Log(_LogType.ltError, msg);
                    ctx.ErrorLog.Log(e);
                    if ((ctx.ImportFlags & _ImportFlags.IgnoreErrors) == 0)
                    {
                        throw new BMException(e, "{0}\r\nDatasource={1}.", e.Message, Name);
                    }

                    msg = String.Format("Exception ignored due to importFlags [{0}].", ctx.ImportFlags);
                    importLog.Log(_LogType.ltWarning, msg);
                    errorLog.Log(_LogType.ltWarning, msg);
                    stopNeeded = true;
                }
            }

            finally
            {
                try
                {
                    if (stopNeeded)
                    {
                        ctx.OptSendItemStop();
                        Pipeline.HandleValue(ctx, "_datasource/_stop", this);
                    }
                }
                finally
                {
                    Pipeline.Stop(ctx);
                }
            }
            importLog.Log(_LogType.ltProgress | _LogType.ltTimerStop, "[{0}]: import ended. {1}.", Name, ctx.GetStats());
        }