Example #1
0
        public async Task <int?> SubmitJob(Job job)
        {
            var request = new JobSubmission()
            {
                Title       = job.Name,
                Description = job.Description,
                UserName    = job.CreatedBy.UserName,
                East        = job.LongitudeEast,
                West        = job.LongitudeWest,
                North       = job.LatitudeNorth,
                South       = job.LatitudeSouth,
                Priority    = 1
            };
            var processorReference = await _processor.StartJob(request);

            if (String.IsNullOrEmpty(processorReference))
            {
                return(null);
            }

            job.JobProcessorReference = processorReference;
            if (job.Id != 0)
            {
                //Job is a resubmission. Use old database record
                job.Status = JobStatus.Submitted;
                _context.Update(job);
            }
            else
            {
                //New job submission
                _context.Jobs.Add(job);
            }
            _context.SaveChanges();

            var savedJob = _context.Jobs.First(j => j.JobProcessorReference == job.JobProcessorReference);

            _notifyService.AddJobNotification(NotificationLevel.Success, savedJob.Id, "Analysis {0} successfully queued for processing.", new[] { job.Name });

            Hangfire.RecurringJob.AddOrUpdate("jobstatus_" + savedJob.Id, () => UpdateJobStatusAsync(savedJob.Id), Cron.Minutely);

            return(savedJob.Id);
        }