public void EnqueueJob(SortJob objJob) { _pendingJobs.Add(objJob); Task.Factory.StartNew(() => { ProcessJob(objJob); } ); }
public ActionResult <SortJob> EnqueueJob([FromForm] int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortStatusJob.Pending, duration: null, input: values, output: null); _sortAsyncJob.EnqueueJob(pendingJob); return(Ok(pendingJob)); }
public async Task <ActionResult <SortJob> > EnqueueAndRunJob(int[] values) { var pendingJob = new SortJob( id: Guid.NewGuid(), status: SortStatusJob.Pending, duration: null, input: values, output: null); var completedJob = await _sortJobProcessor.Process(pendingJob); return(Ok(completedJob)); }
public async Task <SortJob> Process(SortJob job) { _logger.LogInformation("Processing job with ID '{JobId}'.", job.Id); var stopwatch = Stopwatch.StartNew(); var output = job.Input.OrderBy(n => n).ToArray(); await Task.Delay(50000); // NOTE: This is just to simulate a more expensive operation var duration = stopwatch.Elapsed; _logger.LogInformation("Completed processing job with ID '{JobId}'. Duration: '{Duration}'.", job.Id, duration); return(new SortJob( id: job.Id, status: SortStatusJob.Completed, duration: duration, input: job.Input, output: output)); }
private void ProcessJob(SortJob objJob) { _completedJobs.Add(_sortJobProcessor.Process(objJob).Result); }