diff --git a/server/AyaNova/Controllers/JobOperationsController.cs b/server/AyaNova/Controllers/JobOperationsController.cs index c60f074d..cc21f1b4 100644 --- a/server/AyaNova/Controllers/JobOperationsController.cs +++ b/server/AyaNova/Controllers/JobOperationsController.cs @@ -74,6 +74,28 @@ namespace AyaNova.Api.Controllers } + /// + /// Get current job status for a job + /// + /// + /// A single job's current status + [HttpGet("status/{gid}")] + public async Task GetJobStatus([FromRoute] Guid gid) + { + if (serverState.IsClosed) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + + //This is called by the UI to monitor any operation that triggers a job so it really should be available to any logged in user + // if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.ServerJob)) + // { + // return StatusCode(403, new ApiNotAuthorizedResponse()); + // } + + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + return Ok(ApiOkResponse.Response(await JobsBiz.GetJobStatusAsync(gid))); + } + /// @@ -148,7 +170,7 @@ namespace AyaNova.Api.Controllers OpsJob j = new OpsJob(); j.Name = "TestJob"; j.JobType = JobType.TestJob; - await JobsBiz.AddJobAsync(j); + await JobsBiz.AddJobAsync(j); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, $"{j.JobType} {j.Name}"), ct); return Accepted(new { JobId = j.GId });//202 accepted } diff --git a/server/AyaNova/biz/JobStatus.cs b/server/AyaNova/biz/JobStatus.cs index 5efbd771..2b26cd31 100644 --- a/server/AyaNova/biz/JobStatus.cs +++ b/server/AyaNova/biz/JobStatus.cs @@ -7,6 +7,7 @@ namespace AyaNova.Biz /// public enum JobStatus : int { + Absent=0, Sleeping = 1, Running = 2, Completed = 3, diff --git a/server/AyaNova/biz/JobsBiz.cs b/server/AyaNova/biz/JobsBiz.cs index 2a63cb87..8e8d432f 100644 --- a/server/AyaNova/biz/JobsBiz.cs +++ b/server/AyaNova/biz/JobsBiz.cs @@ -138,6 +138,20 @@ namespace AyaNova.Biz await ct.SaveChangesAsync(); } } + + /// + /// Get the status of a job + /// + /// + internal static async Task GetJobStatusAsync(Guid jobId) + { + using (AyContext ct = ServiceProviderProvider.DBContext) + { + var o = await ct.OpsJob.AsNoTracking().SingleOrDefaultAsync(z => z.GId == jobId); + if (o == null) return JobStatus.Absent; + return o.JobStatus; + } + } #endregion Job ops #region PROCESSOR