Skip to content

Commit

Permalink
feat: Added ability to trigger transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Mar 22, 2024
1 parent f747c1e commit c2d817e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/LinkDotNet.Blog.Web/Features/Admin/Settings/SettingsPage.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@page "/settings"
@using LinkDotNet.Blog.Web.Features.Services
@using LinkDotNet.NCronJob
@inject IOptions<ApplicationConfiguration> ApplicationConfiguration
@inject ICacheInvalidator CacheInvalidator
@inject IToastService ToastService
@inject IInstantJobRegistry InstantJobRegistry
@attribute [Authorize]

<div class="container-fluid ms-3">
Expand All @@ -25,6 +27,13 @@
<td>@ApplicationConfiguration.Value.FirstPageCacheDurationInMinutes Minutes</td>
<td><button class="btn btn-warning" id="invalidate-cache" @onclick="InvalidateCache">Invalidate Cache</button></td>
</tr>
<tr>
<td>Run Visit Counter Data Collection</td>
<td>The visit counter data collection is a background job that collects the visit data of the blog posts.<br/>
The job runs every hour (on the hour). The job can be run on demand.</td>
<td></td>
<td><button class="btn btn-warning" id="run-visit-transformer" @onclick="RunVisitTransformer">Run transformer</button></td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -35,4 +44,10 @@
CacheInvalidator.Cancel();
ToastService.ShowInfo("Cache was invalidated.");
}

private void RunVisitTransformer()
{
InstantJobRegistry.AddInstantJob<TransformBlogPostRecordsService>();
ToastService.ShowInfo("Transformer was started.");
}
}
1 change: 0 additions & 1 deletion src/LinkDotNet.Blog.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private static void RegisterServices(WebApplicationBuilder builder)
builder.Services.RegisterServices();
builder.Services.AddStorageProvider(builder.Configuration);
builder.Services.AddResponseCompression();
builder.Services.AddBackgroundServices();

builder.Services.AddHealthChecks()
.AddCheck<DatabaseHealthCheck>("Database");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using LinkDotNet.Blog.Web.Features;
using LinkDotNet.NCronJob;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -15,7 +16,7 @@ public static void AddBackgroundServices(this IServiceCollection services)
options.ServicesStopConcurrently = true;
});

services.AddNCronJob();
services.AddNCronJob(p => p.TimerInterval = TimeSpan.FromSeconds(30));
services.AddCronJob<BlogPostPublisher>(p => p.CronExpression = "* * * * *");
services.AddCronJob<TransformBlogPostRecordsService>(p => p.CronExpression = "0 * * * *");
}
Expand Down
3 changes: 3 additions & 0 deletions src/LinkDotNet.Blog.Web/ServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Services;
using LinkDotNet.Blog.Web.Features.Admin.Sitemap.Services;
using LinkDotNet.Blog.Web.Features.Services;
using LinkDotNet.Blog.Web.RegistrationExtensions;
using Microsoft.Extensions.DependencyInjection;

namespace LinkDotNet.Blog.Web;
Expand All @@ -19,5 +20,7 @@ public static void RegisterServices(this IServiceCollection services)
services.AddSingleton<CacheService>();
services.AddSingleton<ICacheTokenProvider>(s => s.GetRequiredService<CacheService>());
services.AddSingleton<ICacheInvalidator>(s => s.GetRequiredService<CacheService>());

services.AddBackgroundServices();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.Admin.Settings;
using LinkDotNet.Blog.Web.Features.Services;
using LinkDotNet.NCronJob;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

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

Expand Down

0 comments on commit c2d817e

Please sign in to comment.