File tree Expand file tree Collapse file tree 5 files changed +22
-2
lines changed
tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Settings Expand file tree Collapse file tree 5 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
@page " /settings"
2
2
@using LinkDotNet .Blog .Web .Features .Services
3
+ @using LinkDotNet .NCronJob
3
4
@inject IOptions <ApplicationConfiguration > ApplicationConfiguration
4
5
@inject ICacheInvalidator CacheInvalidator
5
6
@inject IToastService ToastService
7
+ @inject IInstantJobRegistry InstantJobRegistry
6
8
@attribute [Authorize]
7
9
8
10
<div class =" container-fluid ms-3" >
25
27
<td >@ApplicationConfiguration.Value.FirstPageCacheDurationInMinutes Minutes</td >
26
28
<td ><button class =" btn btn-warning" id =" invalidate-cache" @onclick =" InvalidateCache" >Invalidate Cache</button ></td >
27
29
</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 >
28
37
</tbody >
29
38
</table >
30
39
</div >
35
44
CacheInvalidator .Cancel ();
36
45
ToastService .ShowInfo (" Cache was invalidated." );
37
46
}
47
+
48
+ private void RunVisitTransformer ()
49
+ {
50
+ InstantJobRegistry .AddInstantJob <TransformBlogPostRecordsService >();
51
+ ToastService .ShowInfo (" Transformer was started." );
52
+ }
38
53
}
Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ private static void RegisterServices(WebApplicationBuilder builder)
38
38
builder . Services . RegisterServices ( ) ;
39
39
builder . Services . AddStorageProvider ( builder . Configuration ) ;
40
40
builder . Services . AddResponseCompression ( ) ;
41
- builder . Services . AddBackgroundServices ( ) ;
42
41
43
42
builder . Services . AddHealthChecks ( )
44
43
. AddCheck < DatabaseHealthCheck > ( "Database" ) ;
Original file line number Diff line number Diff line change
1
+ using System ;
1
2
using LinkDotNet . Blog . Web . Features ;
2
3
using LinkDotNet . NCronJob ;
3
4
using Microsoft . Extensions . DependencyInjection ;
@@ -15,7 +16,7 @@ public static void AddBackgroundServices(this IServiceCollection services)
15
16
options . ServicesStopConcurrently = true ;
16
17
} ) ;
17
18
18
- services . AddNCronJob ( ) ;
19
+ services . AddNCronJob ( p => p . TimerInterval = TimeSpan . FromSeconds ( 30 ) ) ;
19
20
services . AddCronJob < BlogPostPublisher > ( p => p . CronExpression = "* * * * *" ) ;
20
21
services . AddCronJob < TransformBlogPostRecordsService > ( p => p . CronExpression = "0 * * * *" ) ;
21
22
}
Original file line number Diff line number Diff line change 1
1
using LinkDotNet . Blog . Web . Features . Admin . BlogPostEditor . Services ;
2
2
using LinkDotNet . Blog . Web . Features . Admin . Sitemap . Services ;
3
3
using LinkDotNet . Blog . Web . Features . Services ;
4
+ using LinkDotNet . Blog . Web . RegistrationExtensions ;
4
5
using Microsoft . Extensions . DependencyInjection ;
5
6
6
7
namespace LinkDotNet . Blog . Web ;
@@ -19,5 +20,7 @@ public static void RegisterServices(this IServiceCollection services)
19
20
services . AddSingleton < CacheService > ( ) ;
20
21
services . AddSingleton < ICacheTokenProvider > ( s => s . GetRequiredService < CacheService > ( ) ) ;
21
22
services . AddSingleton < ICacheInvalidator > ( s => s . GetRequiredService < CacheService > ( ) ) ;
23
+
24
+ services . AddBackgroundServices ( ) ;
22
25
}
23
26
}
Original file line number Diff line number Diff line change 2
2
using LinkDotNet . Blog . Web ;
3
3
using LinkDotNet . Blog . Web . Features . Admin . Settings ;
4
4
using LinkDotNet . Blog . Web . Features . Services ;
5
+ using LinkDotNet . NCronJob ;
5
6
using Microsoft . Extensions . DependencyInjection ;
6
7
using Microsoft . Extensions . Options ;
7
8
@@ -16,6 +17,7 @@ public void GivenSettingsPage_WhenClicking_InvalidateCacheButton_TokenIsCancelle
16
17
Services . AddScoped ( _ => cacheInvalidator ) ;
17
18
Services . AddScoped ( _ => Options . Create < ApplicationConfiguration > ( new ( ) ) ) ;
18
19
Services . AddScoped ( _ => Substitute . For < IToastService > ( ) ) ;
20
+ Services . AddScoped ( _ => Substitute . For < IInstantJobRegistry > ( ) ) ;
19
21
var cut = Render < SettingsPage > ( ) ;
20
22
var invalidateCacheButton = cut . Find ( "#invalidate-cache" ) ;
21
23
You can’t perform that action at this time.
0 commit comments