[CHANGE] Services view
This commit is contained in:
@@ -5,4 +5,5 @@
|
||||
<MudNavLink Href="/Library" Icon="@Icons.Material.Filled.LocalLibrary" Match="NavLinkMatch.All">Library</MudNavLink>
|
||||
<MudNavLink Href="/Playlists" Icon="@Icons.Material.Filled.ViewList" Match="NavLinkMatch.All">Playlists</MudNavLink>
|
||||
<MudNavLink Href="/Development" Icon="@Icons.Material.Filled.DeveloperMode" Match="NavLinkMatch.All">Development</MudNavLink>
|
||||
<MudNavLink Href="/Services" Icon="@Icons.Material.Filled.MiscellaneousServices" Match="NavLinkMatch.All">Services</MudNavLink>
|
||||
</MudNavMenu>
|
26
Manager.App/Components/Pages/Services.razor
Normal file
26
Manager.App/Components/Pages/Services.razor
Normal file
@@ -0,0 +1,26 @@
|
||||
@page "/Services"
|
||||
@using Manager.App.Services.System
|
||||
|
||||
|
||||
@inject BackgroundServiceManager ServiceManager
|
||||
|
||||
<title>Services</title>
|
||||
|
||||
<MudDataGrid T="ExtendedBackgroundService" MultiSelection Items="@_backgroundServices">
|
||||
<ToolBarContent>
|
||||
<MudText Typo="Typo.h6">Services</MudText>
|
||||
<MudSpacer />
|
||||
<MudTextField T="string" @bind-Value="@_searchText" Immediate
|
||||
Placeholder="Search" Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium"/>
|
||||
</ToolBarContent>
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Name" Title="Service"/>
|
||||
<PropertyColumn Property="x => x.State" Title="Status"/>
|
||||
<PropertyColumn Property="x => x.ExecuteInterval" Title="Execute interval"/>
|
||||
<TemplateColumn></TemplateColumn>
|
||||
</Columns>
|
||||
<PagerContent>
|
||||
<MudDataGridPager T="ExtendedBackgroundService" />
|
||||
</PagerContent>
|
||||
</MudDataGrid>
|
16
Manager.App/Components/Pages/Services.razor.cs
Normal file
16
Manager.App/Components/Pages/Services.razor.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Manager.App.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace Manager.App.Components.Pages;
|
||||
|
||||
public partial class Services : ComponentBase
|
||||
{
|
||||
private string _searchText = "";
|
||||
private List<ExtendedBackgroundService> _backgroundServices = [];
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_backgroundServices = ServiceManager.GetServices();
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@ namespace Manager.App.Services;
|
||||
|
||||
public abstract class ExtendedBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly ManualResetEventSlim _resetEvent = new(true);
|
||||
private TaskCompletionSource _resumeSignal = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly ILogger _logger;
|
||||
public ServiceState State { get; private set; } = ServiceState.Stopped;
|
||||
public CircularBuffer<ServiceProgress> ProgressLog { get; } = new(500);
|
||||
@@ -24,13 +24,20 @@ public abstract class ExtendedBackgroundService : BackgroundService
|
||||
protected sealed override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
State = ServiceState.Running;
|
||||
_logger.LogInformation("Starting background service: {ServiceName}", Name);
|
||||
_logger.LogInformation("Initializing background service: {ServiceName}", Name);
|
||||
await InitializeAsync(stoppingToken);
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Running background service: {ServiceName}", Name);
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
_resetEvent.Wait(stoppingToken);
|
||||
if (State == ServiceState.Paused)
|
||||
{
|
||||
_resumeSignal = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
await _resumeSignal.Task.WaitAsync(stoppingToken);
|
||||
}
|
||||
|
||||
await Task.Delay(ExecuteInterval, stoppingToken);
|
||||
await ExecuteServiceAsync(stoppingToken);
|
||||
}
|
||||
@@ -57,7 +64,6 @@ public abstract class ExtendedBackgroundService : BackgroundService
|
||||
{
|
||||
if (State == ServiceState.Running)
|
||||
{
|
||||
_resetEvent.Reset();
|
||||
State = ServiceState.Paused;
|
||||
_logger.LogInformation("Pauses service: {ServiceName}", Name);
|
||||
}
|
||||
@@ -67,12 +73,13 @@ public abstract class ExtendedBackgroundService : BackgroundService
|
||||
{
|
||||
if (State == ServiceState.Paused)
|
||||
{
|
||||
_resetEvent.Set();
|
||||
State = ServiceState.Running;
|
||||
_logger.LogInformation("Resumes service: {ServiceName}", Name);
|
||||
_resumeSignal.TrySetResult();
|
||||
_logger.LogInformation("Resumed service: {ServiceName}", Name);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task InitializeAsync(CancellationToken stoppingToken);
|
||||
protected abstract Task ExecuteServiceAsync(CancellationToken stoppingToken);
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
|
@@ -1,5 +1,3 @@
|
||||
using Manager.App.Models.System;
|
||||
|
||||
namespace Manager.App.Services.System;
|
||||
|
||||
public class BackgroundServiceManager
|
||||
@@ -11,13 +9,8 @@ public class BackgroundServiceManager
|
||||
_backgroundServices.Add(service);
|
||||
}
|
||||
|
||||
public ListResult<ExtendedBackgroundService> GetServices(string serviceName, int total = 20, int skip = 0)
|
||||
public List<ExtendedBackgroundService> GetServices()
|
||||
{
|
||||
var filtered = string.IsNullOrWhiteSpace(serviceName) ? _backgroundServices.ToArray() : _backgroundServices.Where(x => x.Name.Equals(serviceName, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
|
||||
var results = filtered.OrderDescending()
|
||||
.Skip(skip)
|
||||
.Take(total);
|
||||
return new ListResultReturn<ExtendedBackgroundService>(results.ToList(), filtered.Length);
|
||||
return _backgroundServices.ToList();
|
||||
}
|
||||
}
|
@@ -11,14 +11,20 @@ public class ClientService(IServiceScopeFactory scopeFactory, ILogger<ClientServ
|
||||
private readonly List<YouTubeClient> _clients = [];
|
||||
private CancellationToken _cancellationToken;
|
||||
private ILibraryService? _libraryService;
|
||||
|
||||
protected override async Task ExecuteServiceAsync(CancellationToken stoppingToken)
|
||||
|
||||
protected override async Task InitializeAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
_cancellationToken = stoppingToken;
|
||||
stoppingToken.Register(CancellationRequested);
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
_libraryService = scope.ServiceProvider.GetRequiredService<ILibraryService>();
|
||||
LogProgress("Initializing service...");
|
||||
Pause();
|
||||
}
|
||||
|
||||
protected override async Task ExecuteServiceAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void CancellationRequested()
|
||||
|
Reference in New Issue
Block a user