#173 deleting old long-running-jobd

This commit is contained in:
Hamid Reza Mohammadi 2021-07-07 21:17:41 +04:30
parent e0988bf10d
commit a0a22be220
5 changed files with 56 additions and 1 deletions

View File

@ -29,3 +29,5 @@
</tr>
}
</table>
<a role="button" onclick="cleanUpJobs()" class="actionlink" title="حذف کارهای قدیمی">حذف کارهای قدیمی 🗑</a>

View File

@ -8,6 +8,7 @@ using RSecurityBackend.Models.Generic.Db;
namespace GanjooRazor.Areas.Admin.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class LongRunningJobsModel : PageModel
{
public RLongRunningJobStatus[] Jobs { get; set; }
@ -25,8 +26,20 @@ namespace GanjooRazor.Areas.Admin.Pages
}
}
return Page();
}
public async Task<IActionResult> OnPostCleanupJobsAsync()
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/rjobs/cleanup");
response.EnsureSuccessStatusCode();
}
}
return new JsonResult(true);
}
}
}

View File

@ -269,6 +269,24 @@
});
}
function cleanUpJobs() {
if (!confirm('آیا از حذف همهٔ کارهای موفق و ناموفق تکمیل شده اطمینان دارید؟'))
return;
$.ajax({
type: "POST",
url: '?handler=CleanupJobs',
error: function () {
alert('خطا رخ داد.')
},
success: function () {
alert('انجام شد.')
},
});
}
</script>
</head>

View File

@ -34,6 +34,22 @@ namespace RSecurityBackend.Controllers
return Ok(res.Result);
}
/// <summary>
/// clean up old jobs
/// </summary>
/// <returns></returns>
[HttpDelete("cleanup")]
[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> CleanUp()
{
var res = await _jobService.CleanUp(true, true);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok();
}
/// <summary>
/// constructor
/// </summary>

View File

@ -440,6 +440,12 @@
<param name="failed"></param>
<returns></returns>
</member>
<member name="M:RSecurityBackend.Controllers.RLongRunningJobsControllerBase.CleanUp">
<summary>
clean up old jobs
</summary>
<returns></returns>
</member>
<member name="M:RSecurityBackend.Controllers.RLongRunningJobsControllerBase.#ctor(RSecurityBackend.Services.ILongRunningJobProgressService)">
<summary>
constructor