Пример #1
0
        public bool  Update(mo.ReportProcessorRun reportProcessorRun)
        {
            var result = false;

            try
            {
                if (reportProcessorRun == null)
                {
                    throw new ArgumentNullException("reportProcessorRun");
                }

                _reportProcessorRunRepo.Update(reportProcessorRun);

                result = true;
            }
            catch
            {
                throw;
            }

            return(result);
        }
Пример #2
0
        public bool Add(mo.ReportProcessorRun reportProcessorRun)
        {
            var result = false;

            try
            {
                if (reportProcessorRun == null)
                {
                    throw new ArgumentNullException("reportProcessorRun");
                }

                reportProcessorRun.StartRunTime = DateTime.UtcNow;

                _reportProcessorRunRepo.Insert(reportProcessorRun);

                result = true;
            }
            catch
            {
                throw;
            }

            return(result);
        }
    private int LogProcessorRun()
    {
        var latestrun = _reportProcessorRunService.GetLatestRun();

        var reportProcessorRun = new ent.manager.Entity.Model.Reporting.ReportProcessorRun
                                     ()
        {
            StartRunTime = DateTime.UtcNow,
            ReportsCount = 0,
            Status       = Convert.ToInt32(ReportProcessorRunStatus.processing)
        };

        if (latestrun == null)
        {
            _reportProcessorRunService.Add(reportProcessorRun);

            //log
            _logger.LogWarning("Reporting_Host_First Report Processor Run @ " + DateTime.UtcNow.ToString());

            return(reportProcessorRun.Id);
        }
        else
        {
            if (latestrun.Status == Convert.ToInt32(ReportProcessorRunStatus.failed))
            {
                _reportProcessorRunService.Add(reportProcessorRun);

                _logger.LogWarning("Reporting_Host_After Failed_Report Processor Run @ " + DateTime.UtcNow.ToString());

                return(reportProcessorRun.Id);
            }
            else if (latestrun.Status == Convert.ToInt32(ReportProcessorRunStatus.success))
            {
                if (_isApiTriggered)
                {
                    _reportProcessorRunService.Add(reportProcessorRun);

                    _logger.LogWarning("Reporting_Host - CALLED FROM API @ " + DateTime.UtcNow.ToString());

                    return(reportProcessorRun.Id);
                }
                else
                {
                    var lastRunTime = latestrun.EndRunTime;

                    var timeDiff = DateTime.UtcNow.Subtract(lastRunTime.Value).TotalMinutes;

                    var configTimeDiff = int.Parse(_configuration["ReportProcess:PeriodMinuteSpan"]) * int.Parse(_configuration["ReportProcess:PeriodCountUntilFetch"]);

                    if (timeDiff >= configTimeDiff)
                    {
                        _reportProcessorRunService.Add(reportProcessorRun);

                        _logger.LogWarning("Reporting_Host_After Success_Report Processor Run @ " + DateTime.UtcNow.ToString());

                        return(reportProcessorRun.Id);
                    }
                    else
                    {
                        _logger.LogWarning("Reporting_Host_After Success_NO Report Processor Run @ " + DateTime.UtcNow.ToString());

                        return(-1);
                    }
                }
            }
            else //if (latestrun.Status == Convert.ToInt32(ReportProcessorRunStatus.processing))
            {
                var lastStartRunTime = latestrun.StartRunTime;

                var timeDiff = DateTime.UtcNow.Subtract(lastStartRunTime).TotalMinutes;

                // if the run is within its hour and this report process was tried to be executed, ignore and return -1,
                // in order not to send this email redundandtly due to concurrent access to this process by load balanced instances

                if (timeDiff < 60)
                {
                    return(-1);
                }

                _logger.LogWarning("Reporting_Host_After Success_CurrentProcessing_NO Report Processor Run @ " + DateTime.UtcNow.ToString());

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("Report Processor Didnt Start, the current report processor run is still processing.");
                sb.AppendLine("ReportProcessorRun.Id: " + latestrun.Id + ",  ReportProcessorRun.StartRunTime: " + latestrun.StartRunTime);

                EmailHelper.SendReportFailed(from: _configuration["entSenderEmail"],
                                             toCSL: _configuration["entReportFailedRecipientEmail"],
                                             subject: "manager Report Processor - Last Run didnt finish",
                                             body: sb.ToString());

                return(-1);
            }
        }
    }