Skip to content

Commit c2d817e

Browse files
committed
feat: Added ability to trigger transformer
1 parent f747c1e commit c2d817e

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

src/LinkDotNet.Blog.Web/Features/Admin/Settings/SettingsPage.razor

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
@page "/settings"
22
@using LinkDotNet.Blog.Web.Features.Services
3+
@using LinkDotNet.NCronJob
34
@inject IOptions<ApplicationConfiguration> ApplicationConfiguration
45
@inject ICacheInvalidator CacheInvalidator
56
@inject IToastService ToastService
7+
@inject IInstantJobRegistry InstantJobRegistry
68
@attribute [Authorize]
79

810
<div class="container-fluid ms-3">
@@ -25,6 +27,13 @@
2527
<td>@ApplicationConfiguration.Value.FirstPageCacheDurationInMinutes Minutes</td>
2628
<td><button class="btn btn-warning" id="invalidate-cache" @onclick="InvalidateCache">Invalidate Cache</button></td>
2729
</tr>
30+
<tr>
31+
<td>Run Visit Counter Data Collection</td>
32+
<td>The visit counter data collection is a background job that collects the visit data of the blog posts.<br/>
33+
The job runs every hour (on the hour). The job can be run on demand.</td>
34+
<td></td>
35+
<td><button class="btn btn-warning" id="run-visit-transformer" @onclick="RunVisitTransformer">Run transformer</button></td>
36+
</tr>
2837
</tbody>
2938
</table>
3039
</div>
@@ -35,4 +44,10 @@
3544
CacheInvalidator.Cancel();
3645
ToastService.ShowInfo("Cache was invalidated.");
3746
}
47+
48+
private void RunVisitTransformer()
49+
{
50+
InstantJobRegistry.AddInstantJob<TransformBlogPostRecordsService>();
51+
ToastService.ShowInfo("Transformer was started.");
52+
}
3853
}

src/LinkDotNet.Blog.Web/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ private static void RegisterServices(WebApplicationBuilder builder)
3838
builder.Services.RegisterServices();
3939
builder.Services.AddStorageProvider(builder.Configuration);
4040
builder.Services.AddResponseCompression();
41-
builder.Services.AddBackgroundServices();
4241

4342
builder.Services.AddHealthChecks()
4443
.AddCheck<DatabaseHealthCheck>("Database");

src/LinkDotNet.Blog.Web/RegistrationExtensions/BackgroundServiceRegistrationExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using LinkDotNet.Blog.Web.Features;
23
using LinkDotNet.NCronJob;
34
using Microsoft.Extensions.DependencyInjection;
@@ -15,7 +16,7 @@ public static void AddBackgroundServices(this IServiceCollection services)
1516
options.ServicesStopConcurrently = true;
1617
});
1718

18-
services.AddNCronJob();
19+
services.AddNCronJob(p => p.TimerInterval = TimeSpan.FromSeconds(30));
1920
services.AddCronJob<BlogPostPublisher>(p => p.CronExpression = "* * * * *");
2021
services.AddCronJob<TransformBlogPostRecordsService>(p => p.CronExpression = "0 * * * *");
2122
}

src/LinkDotNet.Blog.Web/ServiceExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Services;
22
using LinkDotNet.Blog.Web.Features.Admin.Sitemap.Services;
33
using LinkDotNet.Blog.Web.Features.Services;
4+
using LinkDotNet.Blog.Web.RegistrationExtensions;
45
using Microsoft.Extensions.DependencyInjection;
56

67
namespace LinkDotNet.Blog.Web;
@@ -19,5 +20,7 @@ public static void RegisterServices(this IServiceCollection services)
1920
services.AddSingleton<CacheService>();
2021
services.AddSingleton<ICacheTokenProvider>(s => s.GetRequiredService<CacheService>());
2122
services.AddSingleton<ICacheInvalidator>(s => s.GetRequiredService<CacheService>());
23+
24+
services.AddBackgroundServices();
2225
}
2326
}

tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Settings/SettingsPageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using LinkDotNet.Blog.Web;
33
using LinkDotNet.Blog.Web.Features.Admin.Settings;
44
using LinkDotNet.Blog.Web.Features.Services;
5+
using LinkDotNet.NCronJob;
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Options;
78

@@ -16,6 +17,7 @@ public void GivenSettingsPage_WhenClicking_InvalidateCacheButton_TokenIsCancelle
1617
Services.AddScoped(_ => cacheInvalidator);
1718
Services.AddScoped(_ => Options.Create<ApplicationConfiguration>(new()));
1819
Services.AddScoped(_ => Substitute.For<IToastService>());
20+
Services.AddScoped(_ => Substitute.For<IInstantJobRegistry>());
1921
var cut = Render<SettingsPage>();
2022
var invalidateCacheButton = cut.Find("#invalidate-cache");
2123

0 commit comments

Comments
 (0)