long running jobs api
This commit is contained in:
parent
a8e2b06e70
commit
4f60edda8d
23
RMuseum/Controllers/RLongRunningJobsController.cs
Normal file
23
RMuseum/Controllers/RLongRunningJobsController.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RSecurityBackend.Controllers;
|
||||
using RSecurityBackend.Services;
|
||||
|
||||
namespace RMuseum.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Long Running Jobs
|
||||
/// </summary>
|
||||
[Produces("application/json")]
|
||||
[Route("api/rjobs")]
|
||||
public class RLongRunningJobsController : RLongRunningJobsControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="jobService">
|
||||
/// </param>
|
||||
public RLongRunningJobsController(ILongRunningJobProgressService jobService) : base(jobService)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
1732
RMuseum/Migrations/20210107093226_LongRunningJobs.Designer.cs
generated
Normal file
1732
RMuseum/Migrations/20210107093226_LongRunningJobs.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
RMuseum/Migrations/20210107093226_LongRunningJobs.cs
Normal file
35
RMuseum/Migrations/20210107093226_LongRunningJobs.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace RMuseum.Migrations
|
||||
{
|
||||
public partial class LongRunningJobs : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LongRunningJobs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(nullable: false),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
Progress = table.Column<double>(nullable: false),
|
||||
StartTime = table.Column<DateTime>(nullable: false),
|
||||
EndTime = table.Column<DateTime>(nullable: false),
|
||||
Step = table.Column<string>(nullable: true),
|
||||
Exception = table.Column<string>(nullable: true),
|
||||
Succeeded = table.Column<bool>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LongRunningJobs", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "LongRunningJobs");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1273,6 +1273,38 @@ namespace RMuseum.Migrations
|
||||
b.ToTable("VerifyQueueItems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RSecurityBackend.Models.Generic.Db.RLongRunningJobStatus", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("EndTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Exception")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Progress")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime>("StartTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Step")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("Succeeded")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LongRunningJobs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RSecurityBackend.Models.Image.RImage", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
||||
@ -1066,6 +1066,18 @@
|
||||
<param name="pictureFileService">
|
||||
</param>
|
||||
</member>
|
||||
<member name="T:RMuseum.Controllers.RLongRunningJobsController">
|
||||
<summary>
|
||||
Long Running Jobs
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.RLongRunningJobsController.#ctor(RSecurityBackend.Services.ILongRunningJobProgressService)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
<param name="jobService">
|
||||
</param>
|
||||
</member>
|
||||
<member name="T:RMuseum.Controllers.RoleController">
|
||||
<summary>
|
||||
roles
|
||||
|
||||
@ -259,6 +259,9 @@ namespace RMuseum
|
||||
//ganjoor service
|
||||
services.AddTransient<IGanjoorService, GanjoorService>();
|
||||
|
||||
//long running job service
|
||||
services.AddTransient<ILongRunningJobProgressService, LongRunningJobProgressServiceEF>();
|
||||
|
||||
//upload limit for IIS
|
||||
services.Configure<IISServerOptions>(options =>
|
||||
{
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using RSecurityBackend.Models.Generic.Db;
|
||||
using RSecurityBackend.Services;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RSecurityBackend.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Long Running Jobs
|
||||
/// </summary>
|
||||
[Produces("application/json")]
|
||||
[Route("api/rjobs")]
|
||||
public abstract class RLongRunningJobsControllerBase : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// get long running jobs
|
||||
/// </summary>
|
||||
/// <param name="succeeded"></param>
|
||||
/// <param name="failed"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Authorize(Policy = SecurableItem.AuditLogEntityShortName + ":" + SecurableItem.ViewOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<RLongRunningJobStatus>))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> Get(bool succeeded = true, bool failed = true)
|
||||
{
|
||||
var res = await _jobService.GetJobs(succeeded, failed);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="jobService">
|
||||
/// </param>
|
||||
public RLongRunningJobsControllerBase(ILongRunningJobProgressService jobService)
|
||||
{
|
||||
_jobService = jobService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Artifact Service
|
||||
/// </summary>
|
||||
protected readonly ILongRunningJobProgressService _jobService;
|
||||
}
|
||||
}
|
||||
@ -379,6 +379,31 @@
|
||||
Artifact Service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RSecurityBackend.Controllers.RLongRunningJobsControllerBase">
|
||||
<summary>
|
||||
Long Running Jobs
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Controllers.RLongRunningJobsControllerBase.Get(System.Boolean,System.Boolean)">
|
||||
<summary>
|
||||
get long running jobs
|
||||
</summary>
|
||||
<param name="succeeded"></param>
|
||||
<param name="failed"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Controllers.RLongRunningJobsControllerBase.#ctor(RSecurityBackend.Services.ILongRunningJobProgressService)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
<param name="jobService">
|
||||
</param>
|
||||
</member>
|
||||
<member name="F:RSecurityBackend.Controllers.RLongRunningJobsControllerBase._jobService">
|
||||
<summary>
|
||||
Artifact Service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RSecurityBackend.Controllers.RoleControllerBase">
|
||||
<summary>
|
||||
User roles
|
||||
@ -2216,6 +2241,14 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.ILongRunningJobProgressService.GetJobs(System.Boolean,System.Boolean)">
|
||||
<summary>
|
||||
Get Jobs
|
||||
</summary>
|
||||
<param name="succeeded"></param>
|
||||
<param name="failed"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.ILongRunningJobProgressService.UpdateJob(System.Guid,System.Double,System.String,System.Boolean,System.String)">
|
||||
<summary>
|
||||
update job
|
||||
@ -2726,6 +2759,14 @@
|
||||
<param name="step"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.Implementation.LongRunningJobProgressServiceEF.GetJobs(System.Boolean,System.Boolean)">
|
||||
<summary>
|
||||
Get Jobs
|
||||
</summary>
|
||||
<param name="succeeded"></param>
|
||||
<param name="failed"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.Implementation.LongRunningJobProgressServiceEF.GetJob(System.Guid)">
|
||||
<summary>
|
||||
Get Job By Id
|
||||
|
||||
@ -25,6 +25,15 @@ namespace RSecurityBackend.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<RLongRunningJobStatus>> GetJob(Guid id);
|
||||
|
||||
/// <summary>
|
||||
/// Get Jobs
|
||||
/// </summary>
|
||||
/// <param name="succeeded"></param>
|
||||
/// <param name="failed"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<RLongRunningJobStatus[]>> GetJobs(bool succeeded = true, bool failed = true);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// update job
|
||||
/// </summary>
|
||||
|
||||
@ -4,6 +4,7 @@ using RSecurityBackend.Models.Auth.Db;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Models.Generic.Db;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -12,7 +13,7 @@ namespace RSecurityBackend.Services.Implementation
|
||||
/// <summary>
|
||||
/// Long Running Job Progress Service
|
||||
/// </summary>
|
||||
public class LongRunningJobProgressServiceEF
|
||||
public class LongRunningJobProgressServiceEF : ILongRunningJobProgressService
|
||||
{
|
||||
/// <summary>
|
||||
/// new job
|
||||
@ -43,6 +44,26 @@ namespace RSecurityBackend.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Jobs
|
||||
/// </summary>
|
||||
/// <param name="succeeded"></param>
|
||||
/// <param name="failed"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<RLongRunningJobStatus[]>> GetJobs(bool succeeded = true, bool failed = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jobs = await _context.LongRunningJobs.Where(j => (succeeded && j.Succeeded == true) || (failed && j.Exception != "")).OrderByDescending(j => j.StartTime).ToArrayAsync();
|
||||
|
||||
return new RServiceResult<RLongRunningJobStatus[]>(jobs);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<RLongRunningJobStatus[]> (null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Job By Id
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user