public JsonResult Cancel(Guid jobId, string queueToken) { return(new JsonResult(_pipelineManager.Cancel(jobId, queueToken, new PipelineRequestTracker() { RemoteAddr = HttpContext.Connection.RemoteIpAddress.ToString() }))); }
public ActionResult Get(string spec, uint count, string outputType) { var gCfg = new GeneratorConfig() { Count = count, Specification = spec, OutputFormat = outputType, PersistenceConfig = new Dictionary <Type, IPersistenceConfig>() { { typeof(FilesystemConfig), new FilesystemConfig() { PersistDirectory = Path.GetTempPath() } } } }; var exDict = new Dictionary <string, string[]>() { { "validationErrors", new string[] { "Unknown error" } } }; try { if (_limits.MaxGETGenerateRecordCountPerJob.HasValue && gCfg.Count > _limits.MaxGETGenerateRecordCountPerJob) { throw new ArgumentException($"The value {gCfg.Count} exceeds the allowed limit", "count"); } // TODO: this doesn't belong here! it's a service config error, not a client input error! if (_limits.MaxGETGenerateRunTime < 60) { throw new ArgumentException("MaxGETGenerateRunTime cannot less than 60"); } var jobWaitMutex = new Semaphore(0, 1); List <PersistenceStageResult> results = null; var rv = StartGeneration(gCfg, false, (p) => { results = p.Results; jobWaitMutex.Release(); }); if (!jobWaitMutex.WaitOne(new TimeSpan(0, 0, (int)_limits.MaxGETGenerateRunTime)) && results == null) { _pipelineManager.Cancel((Guid)rv.Id, rv.QueueToken, new PipelineRequestTracker() { RemoteAddr = "self", Request = "get-simple timeout" }); } else { var fPath = (string)results[0].Meta["path"]; byte[] fContents = System.IO.File.ReadAllBytes(fPath); System.IO.File.Delete(fPath); // could use PhysicalFileResult here maybe? var fsr = File(fContents, $"text/{outputType}"); if (outputType == "csv") { fsr.FileDownloadName = Path.GetFileName((string)results[0].Meta["path"]); } return(fsr); } return(BadRequest("Timeout")); } catch (ArgumentException ae) { exDict = new Dictionary <string, string[]>() { { ae.ParamName ?? "validationErrors", new string[] { ae.Message } } }; } catch (AggregateException ae) { exDict = ae.InnerExceptions .Where(ie => ie is ArgumentException) .ToDictionary(ks => ((ArgumentException)ks).ParamName ?? "unknownParameter", vs => new string[] { vs.Message }); } return(ValidationProblem(new ValidationProblemDetails(exDict))); }