Example #1
0
        private async Task UpdateProStatusAsync(Job job)
        {
            if (job.ProActivation.ProcessingStatus == JobStatus.GeneratingOutput)
            {
                Console.WriteLine("Data download archive still generating for: " + job.Id);
                return;
            }

            // Update status and begin generating outputs if required
            var newStatus = await _processor.GetStatus(job.ProActivation.JobProcessorReference, job.ProActivation.ProcessingStatus);

            if (newStatus == JobStatus.Completed && job.ProActivation.ProcessingStatus != JobStatus.Completed)
            {
                job.ProActivation.ProcessingStatus = JobStatus.GeneratingOutput;
                _context.Update(job);
                _context.SaveChanges();
                try {
                    var data = await _processor.GetReportData(job.JobProcessorReference);

                    _outputPersistence.PersistData(job.Id, data);
                    job.ProActivation.ProcessingStatus = JobStatus.Completed;
                    _context.Update(job);
                    _context.SaveChanges();
                } catch (Exception e) {
                    _logger.LogError("Could not persist data download. " + e.Message);
                    job.ProActivation.ProcessingStatus = JobStatus.Failed;
                    _context.Update(job);
                    _context.SaveChanges();
                }
            }
            else
            {
                if (job.ProActivation.ProcessingStatus != newStatus)
                {
                    job.ProActivation.ProcessingStatus = newStatus;
                    _context.Update(job);
                    _context.SaveChanges();
                }
            }

            if (job.ProActivation.ProcessingStatus == JobStatus.Failed || job.ProActivation.ProcessingStatus == JobStatus.Completed)
            {
                Hangfire.RecurringJob.RemoveIfExists("prostatus_" + job.Id);
            }

            if (job.ProActivation.ProcessingStatus == JobStatus.Completed)
            {
                _notifyService.AddJobNotification(NotificationLevel.Information, job.Id, "{0}: pro data ready for download", new[] { job.Name });
            }
        }