From 9e31c8b135d39bf9c06f6a52278e539bad3f8f7e Mon Sep 17 00:00:00 2001 From: chsakell Date: Tue, 4 Oct 2016 11:04:40 +0300 Subject: [PATCH] added test reccurent task using ReccurentTasks --- Startup.cs | 31 +++++++++++++++++++++++++++++++ project.json | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Startup.cs b/Startup.cs index 58ab3d5..c17084a 100644 --- a/Startup.cs +++ b/Startup.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging; using LiveGameFeed.Core.Mappings; using LiveGameFeed.Core.MvcTimer; using Newtonsoft.Json.Serialization; +using RecurrentTasks; namespace LiveGameFeed { @@ -53,6 +54,9 @@ namespace LiveGameFeed new DefaultContractResolver()); services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true); + + services.AddTask(); + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -85,6 +89,33 @@ namespace LiveGameFeed app.UseSignalR(); LiveGameDbInitializer.Initialize(app.ApplicationServices); + + app.StartTask(TimeSpan.FromSeconds(15)); } } + + public class SampleTask : IRunnable + { + private ILogger logger; + + private SampleTaskRunHistory runHistory; + + public SampleTask(ILogger 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 Messages { get; } = new List(); + } } diff --git a/project.json b/project.json index c4bb6ab..723d6e5 100644 --- a/project.json +++ b/project.json @@ -22,7 +22,8 @@ "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "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": {