[backend/razor] Add batch retry functionality to the queue dashboard (ISH-494)
This commit is contained in:
parent
13614c2201
commit
1e650d8649
3 changed files with 47 additions and 2 deletions
|
@ -98,7 +98,6 @@ public class AdminController(
|
|||
}
|
||||
|
||||
[HttpPost("queue/jobs/{id::guid}/retry")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
|
||||
public async Task RetryQueueJob(Guid id)
|
||||
|
@ -109,6 +108,32 @@ public class AdminController(
|
|||
await queueSvc.RetryJobAsync(job);
|
||||
}
|
||||
|
||||
[HttpPost("queue/{queue}/retry-all")]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
public async Task RetryFailedJobs(string queue)
|
||||
{
|
||||
var jobs = db.Jobs
|
||||
.Where(p => p.Queue == queue && p.Status == Job.JobStatus.Failed)
|
||||
.AsChunkedAsyncEnumerable(10);
|
||||
|
||||
await foreach (var job in jobs)
|
||||
await queueSvc.RetryJobAsync(job);
|
||||
}
|
||||
|
||||
[HttpPost("queue/{queue}/retry-range/{from::guid}/{to::guid}")]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
public async Task RetryRange(string queue, Guid from, Guid to)
|
||||
{
|
||||
var jobs = db.Jobs
|
||||
.Where(p => p.Queue == queue && p.Status == Job.JobStatus.Failed)
|
||||
.Where(p => p.Id >= from && p.Id <= to)
|
||||
.AsChunkedAsyncEnumerable(10);
|
||||
|
||||
await foreach (var job in jobs)
|
||||
await queueSvc.RetryJobAsync(job);
|
||||
}
|
||||
|
||||
|
||||
[UseNewtonsoftJson]
|
||||
[HttpGet("activities/notes/{id}")]
|
||||
[OverrideResultType<ASNote>]
|
||||
|
|
|
@ -91,7 +91,13 @@ else
|
|||
}
|
||||
else
|
||||
{
|
||||
<p>Listing @Model.TotalCount <span class="status-@Model.Filter.Value.ToString().ToLowerInvariant()">@Model.Filter.Value.ToString().ToLowerInvariant()</span> <b>@Model.Queue</b> jobs.</p>
|
||||
<p>
|
||||
Listing @Model.TotalCount <span class="status-@Model.Filter.Value.ToString().ToLowerInvariant()">@Model.Filter.Value.ToString().ToLowerInvariant()</span> <b>@Model.Queue</b> jobs.
|
||||
@if (Model.Filter is Job.JobStatus.Failed)
|
||||
{
|
||||
<span>Batch retry: <a class="fake-link" onclick="retryAllFailed('@Model.Queue')">all failed</a> / <a class="fake-link" onclick="retryAllOnPage('@Model.Queue')">all on this page</a></span>
|
||||
}
|
||||
</p>
|
||||
}
|
||||
|
||||
<table class="auto-table">
|
||||
|
|
|
@ -48,4 +48,18 @@ async function callApiMethod(route) {
|
|||
async function retry(id) {
|
||||
await callApiMethod(`/api/iceshrimp/admin/queue/jobs/${id}/retry`);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
async function retryAllFailed(queue) {
|
||||
await callApiMethod(`/api/iceshrimp/admin/queue/${queue}/retry-all`);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
async function retryAllOnPage(queue) {
|
||||
const elements = document.getElementsByClassName("uuid");
|
||||
const items = Array.prototype.map.call(elements, x => x.textContent).sort();
|
||||
const first = items[0];
|
||||
const last = items[items.length - 1];
|
||||
await callApiMethod(`/api/iceshrimp/admin/queue/${queue}/retry-range/${first}/${last}`);
|
||||
window.location.reload();
|
||||
}
|
Loading…
Add table
Reference in a new issue