This commit is contained in:
2020-06-16 17:47:50 +00:00
parent 0c7884b0d5
commit efd00fa51d
3 changed files with 38 additions and 1 deletions

View File

@@ -74,6 +74,28 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Get current job status for a job
/// </summary>
/// <param name="gid"></param>
/// <returns>A single job's current status</returns>
[HttpGet("status/{gid}")]
public async Task<IActionResult> 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)));
}
/// <summary>
@@ -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
}

View File

@@ -7,6 +7,7 @@ namespace AyaNova.Biz
/// </summary>
public enum JobStatus : int
{
Absent=0,
Sleeping = 1,
Running = 2,
Completed = 3,

View File

@@ -138,6 +138,20 @@ namespace AyaNova.Biz
await ct.SaveChangesAsync();
}
}
/// <summary>
/// Get the status of a job
/// </summary>
/// <param name="jobId"></param>
internal static async Task<JobStatus> 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