WIP: p2 plugin
Some checks failed
Build Docker Images / test (map[name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Failing after 1m14s
Build Docker Images / test (map[name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Failing after 1m10s
Build Docker Images / build-and-push (map[image_suffix:morska name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Failing after 1m12s
Build Docker Images / build-and-push (map[image_suffix:pedrollopl name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Failing after 1m7s
Some checks failed
Build Docker Images / test (map[name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Failing after 1m14s
Build Docker Images / test (map[name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Failing after 1m10s
Build Docker Images / build-and-push (map[image_suffix:morska name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Failing after 1m12s
Build Docker Images / build-and-push (map[image_suffix:pedrollopl name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Failing after 1m7s
This commit is contained in:
104
DiunaBI.UI.Shared/Services/JobService.cs
Normal file
104
DiunaBI.UI.Shared/Services/JobService.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using DiunaBI.Application.DTOModels.Common;
|
||||
using DiunaBI.Domain.Entities;
|
||||
|
||||
namespace DiunaBI.UI.Shared.Services;
|
||||
|
||||
public class JobService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public JobService(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public async Task<PagedResult<QueueJob>> GetJobsAsync(int page = 1, int pageSize = 50, JobStatus? status = null, JobType? jobType = null, Guid? layerId = null)
|
||||
{
|
||||
var start = (page - 1) * pageSize;
|
||||
var query = $"Jobs?start={start}&limit={pageSize}";
|
||||
|
||||
if (status.HasValue)
|
||||
query += $"&status={(int)status.Value}";
|
||||
|
||||
if (jobType.HasValue)
|
||||
query += $"&jobType={(int)jobType.Value}";
|
||||
|
||||
if (layerId.HasValue)
|
||||
query += $"&layerId={layerId.Value}";
|
||||
|
||||
var response = await _httpClient.GetAsync(query);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<PagedResult<QueueJob>>(json, _jsonOptions);
|
||||
|
||||
return result ?? new PagedResult<QueueJob>();
|
||||
}
|
||||
|
||||
public async Task<QueueJob?> GetJobByIdAsync(Guid id)
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"Jobs/{id}");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<QueueJob>();
|
||||
}
|
||||
|
||||
public async Task<bool> RetryJobAsync(Guid id)
|
||||
{
|
||||
var response = await _httpClient.PostAsync($"Jobs/{id}/retry", null);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> CancelJobAsync(Guid id)
|
||||
{
|
||||
var response = await _httpClient.DeleteAsync($"Jobs/{id}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<JobStats?> GetStatsAsync()
|
||||
{
|
||||
var response = await _httpClient.GetAsync("Jobs/stats");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<JobStats>();
|
||||
}
|
||||
|
||||
public async Task<CreateJobResult?> CreateJobForLayerAsync(Guid layerId)
|
||||
{
|
||||
var response = await _httpClient.PostAsync($"Jobs/create-for-layer/{layerId}", null);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<CreateJobResult>();
|
||||
}
|
||||
}
|
||||
|
||||
public class JobStats
|
||||
{
|
||||
public int Pending { get; set; }
|
||||
public int Running { get; set; }
|
||||
public int Completed { get; set; }
|
||||
public int Failed { get; set; }
|
||||
public int Retrying { get; set; }
|
||||
public int Total { get; set; }
|
||||
}
|
||||
|
||||
public class CreateJobResult
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public Guid JobId { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public bool Existing { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user