public IActionResult SubmitJob([FromBody] JobSubmission submission) { if (submission == null) { return(this.BadRequest(new { Error = $"Submission body invalid" })); } Log.Information( $"Submit job {submission.QueueId}:{submission.JobId} requested by {this.Request.HttpContext.Connection.RemoteIpAddress}", submission); if (submission.QueueId == null) { return(this.BadRequest(new { Error = $"No QueueId" })); } if (submission.Data == null) { submission.Data = new ExpandoObject(); } Job j = new Job(submission.Data, submission.JobId, null, submission.PreviousJobIds); try { Engine.QueueJob(submission.QueueId, j); } catch (Exception e) { Log.Error(e, $"Submit job failed"); return(this.StatusCode(500, new { message = $"Failed to submit job: {e.Message}" })); } return(this.Ok()); }
public async Task <Guid?> SubmitDataPackage(DataPackage package, List <AvailableVariable> variables) { var request = new JobSubmission() { Title = "Data Package API Request", Description = "", UserName = package.CreatedBy.UserName, East = package.LongitudeEast, West = package.LongitudeWest, North = package.LatitudeNorth, South = package.LatitudeSouth, Priority = 2 }; var processorReference = await _processor.StartDataPackage(request, package.DataRequestedTime, package.Year, package.Month, package.Day, variables.Select(v => v.Id).ToList()); if (String.IsNullOrEmpty(processorReference)) { return(null); } package.JobProcessorReference = processorReference; package.RequestComponents = System.Text.Json.JsonSerializer.Serialize(variables); _context.DataPackages.Add(package); _context.SaveChanges(); var savedPackage = _context.DataPackages.First(j => j.JobProcessorReference == package.JobProcessorReference); Hangfire.RecurringJob.AddOrUpdate("pkgstatus" + savedPackage.Id, () => UpdatePackageStatusAsync(package.Id), Cron.Minutely); _notifyService.AddUserNotification(NotificationLevel.Success, package.CreatedBy.Id, "Requested a data package using the API: {0}.", new[] { package.Id.ToString() }); return(savedPackage.Id); }
public IActionResult SubmitJobExample() { dynamic eo = new ExpandoObject(); eo.Example = "hi"; JobSubmission js = new JobSubmission { QueueId = "EXAMPLE", Data = eo, JobId = "123123", PreviousJobIds = new[] { "ASDSAD", "SASAB" } }; return(this.Json(js)); }
public void CreateJobSubmissionTest() { JobSubmission entity = JobSubmission.InstantiateForInsert(); entity.Candidate = new Candidate(10795); entity.JobOrder = new JobOrder(33); CreateResponse response = bullhornClient.insertEntity <JobSubmission>(JobSubmission.EntityType, entity) as CreateResponse; this.entityId = response.ChangedEntityId; this.deleteType = JobSubmission.EntityType; JobSubmission newEntity = bullhornClient.findEntity <JobSubmission>(JobSubmission.EntityType, response.ChangedEntityId); runAssertions(response, entity, newEntity); }
public async Task <string> StartDataPackage(JobSubmission job, RequestedTime dateMode, int?year, int?month, int?day, List <string> variables) { var time = new TimeMode(); if (dateMode == RequestedTime.Before) { time.Kind = "before"; time.Date = new Date() { Year = year.Value, Month = month, Day = day }; } else if (dateMode == RequestedTime.Exact) { time.Kind = "exact"; time.Date = new Date() { Year = year.Value, Month = month, Day = day }; } else { time.Kind = "latest"; } var command = new JobSubmissionRequest() { East = job.East, West = job.West, North = job.North, South = job.South, Variables = GetCustomRequest(variables), TimeMode = time }; try { var result = await _connection.SubmitJobAsync(command); return(result.Id.ToString()); } catch (Exception e) { _logger.LogCritical("Job could not be submitted to the geotemporal engine. The error was: " + e.Message); return(null); } }
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); }
public async Task SubmitJob(int period, string collectionName, string userName, string email, IFormFile file, CancellationToken cancellationToken) { if (file == null) { return; } var collection = await _collectionService.GetCollectionAsync(collectionName, cancellationToken); var fileName = Path.GetFileName(file.FileName); await(await _storageService.GetAzureStorageReferenceService(_azureStorageConfig.ConnectionString, collection.StorageReference)) .SaveAsync(fileName, file.OpenReadStream(), cancellationToken); try { var job = new JobSubmission { CollectionName = collection.CollectionTitle, FileName = fileName, FileSizeBytes = file.Length, SubmittedBy = userName, NotifyEmail = email, StorageReference = collection.StorageReference, Period = period, CollectionYear = collection.CollectionYear }; // add to the queue await _jobService.SubmitJob(job, cancellationToken); } catch (Exception ex) { _logger.LogError($"Error trying to submit ALLF file with name : {file.Name}", ex); throw; } }
public async Task <string> StartProJob(JobSubmission job) { var command = new JobSubmissionRequest() { East = job.East, West = job.West, North = job.North, South = job.South, Variables = GetReportRequest(true), TimeMode = new TimeMode { Kind = "latest", Date = null } }; try { var result = await _connection.SubmitJobAsync(command); return(result.Id.ToString()); } catch (Exception) { _logger.LogCritical("Job could not be submitted to EcoSet."); return(""); } }
public async Task <string> StartJob(JobSubmission job) { var command = new JobSubmissionRequest() { East = job.East, West = job.West, North = job.North, South = job.South, Variables = GetReportRequest(false), TimeMode = new TimeMode { Kind = "latest", Date = null } }; try { var result = await _connection.SubmitJobAsync(command); return(result.Id.ToString()); } catch (Exception e) { _logger.LogCritical("Job could not be submitted to the geotemporal engine. The error was: " + e.Message); return(null); } }
public async Task <bool> ActivateProFeatures(int jobId, string userId) { var job = _context.Jobs .Include(m => m.CreatedBy) .Include(m => m.ProActivation) .FirstOrDefault(m => m.Id == jobId); if (job == null) { throw new ArgumentException("An invalid job id was passed to the service"); } // NB the user activating is not necessarily the job creator, but could be an admin. var user = _context.Users.FirstOrDefault(u => u.Id == userId); if (user == null) { throw new ArgumentException("An invalid user id was passed to the app service"); } var isAdmin = await _userManager.IsInRoleAsync(user, "Admin"); if (!isAdmin && user.Credits == 0 && _appOptions.PaymentsEnabled) { return(false); } // Allow reactivation by admin if (job.ProActivation != null && !isAdmin) { throw new ArgumentException("The analysis has already been activated"); } // Submit processing for GeoTIFF output 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 = 2 }; var processorReference = await _processor.StartProJob(request); if (String.IsNullOrEmpty(processorReference)) { return(false); } if (!isAdmin && _appOptions.PaymentsEnabled) { user.Credits = user.Credits - 1; } var activation = new ProActivation() { //Id = Guid.NewGuid(), UserIdOfPurchaser = user.Id, TimeOfPurchase = DateTime.Now, CreditsSpent = 1, ProcessingStatus = JobStatus.Submitted, JobProcessorReference = processorReference }; job.ProActivation = activation; _context.Update(job); _context.Update(user); _context.SaveChanges(); Hangfire.RecurringJob.AddOrUpdate("prostatus_" + job.Id, () => UpdateProStatusAsync(job.Id), Cron.Minutely); if (!isAdmin && _appOptions.PaymentsEnabled) { _notifyService.AddJobNotification(NotificationLevel.Success, job.Id, "You used 1 credit to upgrade '{0}' to premium.", new string[] { job.Name }); if (user.Credits <= 3 && user.Credits > 0) { _notifyService.AddUserNotification(NotificationLevel.Information, user.Id, "Your credits are running low. You only have enough for {0} more premium activations.", new string[] { user.Credits.ToString() }); } else if (user.Credits == 0) { _notifyService.AddUserNotification(NotificationLevel.Information, user.Id, "You're out of credits, and will not be able to activate premium datasets unless you top up.", new string[] {}); } } else if (!_appOptions.PaymentsEnabled) { _notifyService.AddJobNotification(NotificationLevel.Success, job.Id, "Your request for a high-resolution data package for '{0}' has entered the queue.", new string[] { job.Name }); } return(true); }