This commit is contained in:
2020-05-22 21:09:29 +00:00
parent 6060d5a6d1
commit 8c546b3779
4 changed files with 52 additions and 4 deletions

View File

@@ -80,11 +80,11 @@ namespace AyaNova.Api.Controllers
/// Get Operations log for a job
/// </summary>
/// <param name="gid"></param>
/// <returns>A tag</returns>
/// <returns>A single job's log</returns>
[HttpGet("logs/{gid}")]
public async Task<IActionResult> GetLogs([FromRoute] Guid gid)
{
if (serverState.IsClosed)
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.ServerJob))
@@ -105,6 +105,34 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Get Operations log for all jobs
/// </summary>
/// <returns>Log for all jobs in system</returns>
[HttpGet("logs/all-jobs")]
public async Task<IActionResult> GetAllLogs()
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.ServerJob))
{
return StatusCode(403, new ApiNotAuthorizedResponse());
}
if (!ModelState.IsValid)
{
return BadRequest(new ApiErrorResponse(ModelState));
}
//Instantiate the business object handler
JobOperationsBiz biz = new JobOperationsBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
List<JobOperationsLogInfoItem> l = await biz.GetAllJobsLogsListAsync();
return Ok(ApiOkResponse.Response(l));
}

View File

@@ -86,6 +86,27 @@ namespace AyaNova.Biz
return ret;
}
//Get list of logs for job
internal async Task<List<JobOperationsLogInfoItem>> GetAllJobsLogsListAsync()
{
List<JobOperationsLogInfoItem> ret = new List<JobOperationsLogInfoItem>();
var l = await ct.OpsJobLog
.OrderByDescending(z => z.Created)
.ToListAsync();
foreach (OpsJobLog i in l)
{
JobOperationsLogInfoItem o = new JobOperationsLogInfoItem();
o.Created = i.Created;
o.StatusText = i.StatusText;
ret.Add(o);
}
return ret;
}
#endregion controller routes

View File

@@ -401,7 +401,7 @@ namespace AyaNova.Biz
var JobDescription = $"{job.Name} {job.JobType.ToString()}";
if (job.SubType != JobSubType.NotSet)
JobDescription += $":{job.SubType}";
await LogJobAsync(job.GId, $"Process job \"{JobDescription}\"", ct);
log.LogDebug($"ProcessJobAsync -> Processing job {JobDescription}");
IJobObject o = null;

View File

@@ -1,4 +1,3 @@
using AyaNova.Biz;
using System;
namespace AyaNova.Models