public IActionResult Post(JobRequest payload) { try { if (payload == null || payload.Input.Count == 0) { return(StatusCode(422, "Invalid payload")); } Guid jobId = Guid.NewGuid(); _context.JobsManager.Add(new Database.Entity.JobsManager { JobId = jobId.ToString(), JobItem = JsonConvert.SerializeObject(payload.Input), ReceivedTime = DateTime.UtcNow, Status = JobStatus.Initiated }); _context.SaveChangesAsync(); var jobResponse = new JobResponse() { JobId = jobId.ToString(), ReceivedTime = DateTime.UtcNow, Status = JobStatus.Initiated, Url = $"https://localhost:44365/Jobs/GetJob?jobId={jobId.ToString()}", Message = $"A seperate task in created to sort thr input array Use /Jobs/GetJob endpoint with JobId to get job details" }; // Enqueue a background work item _taskQueue.QueueBackgroundWorkItem(async token => _sortService.SortIntsAsync(jobId.ToString())); return(Accepted(jobResponse)); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(500, ex.Message)); } }