added test reccurent task using ReccurentTasks

This commit is contained in:
chsakell
2016-10-04 11:04:40 +03:00
parent 2b7a82666b
commit 9e31c8b135
2 changed files with 33 additions and 1 deletions

View File

@@ -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>();
}
} }

View File

@@ -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": {