Skip to content

Commit

Permalink
dashboard proto
Browse files Browse the repository at this point in the history
  • Loading branch information
coronabytes committed Jan 1, 2024
1 parent 8913d02 commit e5c5b16
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Core.TaskProcessor.Dashboard/Core.TaskProcessor.Dashboard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core.TaskProcessor\Core.TaskProcessor.csproj" />
</ItemGroup>
</Project>
59 changes: 59 additions & 0 deletions Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;

namespace Core.TaskProcessor.Dashboard
{
public class TaskProcessorDashboardOptions
{
public string Prefix { get; set; } = "/taskprocessor";
public Func<HttpContext, Task<string>> TenantProvider { get; set; } = _ => Task.FromResult("core");
}

public static class TaskProcessorDashboardExtensions
{
public static void AddTaskProcessorDashboard(this IServiceCollection services, TaskProcessorDashboardOptions options)
{
services.AddSingleton(options);
}

public static void MapTaskProcessorDashboard(this WebApplication app)
{
var options = app.Services.GetRequiredService<TaskProcessorDashboardOptions>();

app.MapGet($"{options.Prefix}/batches", async (ITaskProcessor proc) =>
{
return await proc.GetBatchesAsync("core", 0, 50);
});

app.MapGet($"{options.Prefix}/schedules", async (ITaskProcessor proc) =>
{
return await proc.GetSchedulesAsync("core", 0, 50);
});

app.MapGet($"{options.Prefix}/queues", async (ITaskProcessor proc) =>
{
return await proc.GetQueuesAsync();
});//.RequireAuthorization("taskprocessor_admin");

app.MapPost($"{options.Prefix}/batch/{{batchId}}/cancel", async (ITaskProcessor proc, [FromRoute] string batchId) =>
{
return await proc.CancelBatchAsync(batchId);
});//.RequireAuthorization("taskprocessor_admin");

app.MapPost($"{options.Prefix}/schedule/{{scheduleId}}/cancel", async (ITaskProcessor proc, [FromRoute] string scheduleId) =>
{

return await proc.CancelScheduleAsync(scheduleId, );

Check failure on line 48 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

Invalid expression term ')'

Check failure on line 48 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

Invalid expression term ')'

Check failure on line 48 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

Invalid expression term ')'

Check failure on line 48 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

Invalid expression term ')'

Check failure on line 48 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

Invalid expression term ')'
});//.RequireAuthorization("taskprocessor_admin");

app.MapPost($"{options.Prefix}/schedule/{{scheduleId}}/fire", async (ITaskProcessor proc, [FromRoute] string batchId) =>
{
return await proc.CancelBatchAsync(batchId);
});//.RequireAuthorization("taskprocessor_admin");

app.usesta

Check failure on line 56 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

; expected

Check failure on line 56 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

; expected

Check failure on line 56 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

; expected

Check failure on line 56 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

; expected

Check failure on line 56 in Core.TaskProcessor.Dashboard/TaskProcessorDashboardExtensions.cs

View workflow job for this annotation

GitHub Actions / build (8.x)

; expected
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core.TaskProcessor.Dashboard\Core.TaskProcessor.Dashboard.csproj" />
<ProjectReference Include="..\Core.TaskProcessor\Core.TaskProcessor.csproj" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions Core.TaskProcessor.SampleWebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Core.TaskProcessor;
using Core.TaskProcessor.Dashboard;
using Core.TaskProcessor.SampleWebApi.Services;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -20,9 +21,19 @@
UseHostedService = true,
UseCronSeconds = true
});
builder.Services.AddTaskProcessorDashboard(new TaskProcessorDashboardOptions
{

});

builder.Services.AddScoped<ISomeScopedService, SomeScopedService>();

builder.Services.AddAuthorizationBuilder()
.AddPolicy("taskprocessor_admin", policy =>
policy
.RequireRole("taskprocessor"));


var app = builder.Build();

if (app.Environment.IsDevelopment())
Expand All @@ -34,6 +45,7 @@
app.UseAuthorization();

app.MapControllers();
app.MapTaskProcessorDashboard();

{
var proc = app.Services.GetRequiredService<ITaskProcessor>();
Expand Down
8 changes: 7 additions & 1 deletion Core.TaskProcessor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.TaskProcessor", "Core.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.TaskProcessor.Tests", "Core.TaskProcessor.Tests\Core.TaskProcessor.Tests.csproj", "{47028D34-1E6E-4968-844D-080373CB5647}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.TaskProcessor.SampleWebApi", "Core.TaskProcessor.SampleWebApi\Core.TaskProcessor.SampleWebApi.csproj", "{A37C75D6-DD7A-4368-BAA0-CF6ACCAD8C8A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.TaskProcessor.SampleWebApi", "Core.TaskProcessor.SampleWebApi\Core.TaskProcessor.SampleWebApi.csproj", "{A37C75D6-DD7A-4368-BAA0-CF6ACCAD8C8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.TaskProcessor.Dashboard", "Core.TaskProcessor.Dashboard\Core.TaskProcessor.Dashboard.csproj", "{95F89C4F-A7D8-4177-BC64-EF15E73D9229}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{A37C75D6-DD7A-4368-BAA0-CF6ACCAD8C8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A37C75D6-DD7A-4368-BAA0-CF6ACCAD8C8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A37C75D6-DD7A-4368-BAA0-CF6ACCAD8C8A}.Release|Any CPU.Build.0 = Release|Any CPU
{95F89C4F-A7D8-4177-BC64-EF15E73D9229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95F89C4F-A7D8-4177-BC64-EF15E73D9229}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95F89C4F-A7D8-4177-BC64-EF15E73D9229}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95F89C4F-A7D8-4177-BC64-EF15E73D9229}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit e5c5b16

Please sign in to comment.