mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
added test reccurent task using ReccurentTasks
This commit is contained in:
31
Startup.cs
31
Startup.cs
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using LiveGameFeed.Core.Mappings;
|
using LiveGameFeed.Core.Mappings;
|
||||||
using LiveGameFeed.Core.MvcTimer;
|
using LiveGameFeed.Core.MvcTimer;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using RecurrentTasks;
|
||||||
|
|
||||||
namespace LiveGameFeed
|
namespace LiveGameFeed
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,9 @@ namespace LiveGameFeed
|
|||||||
new DefaultContractResolver());
|
new DefaultContractResolver());
|
||||||
|
|
||||||
services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true);
|
services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true);
|
||||||
|
|
||||||
|
services.AddTask<SampleTask>();
|
||||||
|
services.AddSingleton<SampleTaskRunHistory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
@@ -85,6 +89,33 @@ namespace LiveGameFeed
|
|||||||
app.UseSignalR();
|
app.UseSignalR();
|
||||||
|
|
||||||
LiveGameDbInitializer.Initialize(app.ApplicationServices);
|
LiveGameDbInitializer.Initialize(app.ApplicationServices);
|
||||||
|
|
||||||
|
app.StartTask<SampleTask>(TimeSpan.FromSeconds(15));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SampleTask : IRunnable
|
||||||
|
{
|
||||||
|
private ILogger logger;
|
||||||
|
|
||||||
|
private SampleTaskRunHistory runHistory;
|
||||||
|
|
||||||
|
public SampleTask(ILogger<SampleTask> logger, SampleTaskRunHistory runHistory)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.runHistory = runHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run(TaskRunStatus taskRunStatus)
|
||||||
|
{
|
||||||
|
var msg = string.Format("Run at: {0}", DateTimeOffset.Now);
|
||||||
|
runHistory.Messages.Add(msg);
|
||||||
|
logger.LogDebug(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SampleTaskRunHistory
|
||||||
|
{
|
||||||
|
public List<string> Messages { get; } = new List<string>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
"Microsoft.Extensions.Logging": "1.0.0",
|
"Microsoft.Extensions.Logging": "1.0.0",
|
||||||
"Microsoft.Extensions.Logging.Console": "1.0.0",
|
"Microsoft.Extensions.Logging.Console": "1.0.0",
|
||||||
"Microsoft.Extensions.Logging.Debug": "1.0.0",
|
"Microsoft.Extensions.Logging.Debug": "1.0.0",
|
||||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
|
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
|
||||||
|
"RecurrentTasks": "3.0.0-beta1"
|
||||||
},
|
},
|
||||||
|
|
||||||
"tools": {
|
"tools": {
|
||||||
|
|||||||
Reference in New Issue
Block a user