diff --git a/Shift.Cache.Redis/Properties/AssemblyInfo.cs b/Shift.Cache.Redis/Properties/AssemblyInfo.cs
index 452792b..14e1a33 100644
--- a/Shift.Cache.Redis/Properties/AssemblyInfo.cs
+++ b/Shift.Cache.Redis/Properties/AssemblyInfo.cs
@@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
diff --git a/Shift.Cache.Redis/Shift.Cache.Redis.csproj b/Shift.Cache.Redis/Shift.Cache.Redis.csproj
index 260c232..2dc49be 100644
--- a/Shift.Cache.Redis/Shift.Cache.Redis.csproj
+++ b/Shift.Cache.Redis/Shift.Cache.Redis.csproj
@@ -34,8 +34,8 @@
..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll
True
-
- ..\packages\StackExchange.Redis.1.2.4\lib\net46\StackExchange.Redis.dll
+
+ ..\packages\StackExchange.Redis.1.2.6\lib\net46\StackExchange.Redis.dll
True
diff --git a/Shift.Cache.Redis/packages.config b/Shift.Cache.Redis/packages.config
index d93ffcf..92413b7 100644
--- a/Shift.Cache.Redis/packages.config
+++ b/Shift.Cache.Redis/packages.config
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/Shift.DataLayer/Properties/AssemblyInfo.cs b/Shift.DataLayer/Properties/AssemblyInfo.cs
index 2d6d488..5235fb6 100644
--- a/Shift.DataLayer/Properties/AssemblyInfo.cs
+++ b/Shift.DataLayer/Properties/AssemblyInfo.cs
@@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
diff --git a/Shift.DataLayer/Shift.DataLayer.csproj b/Shift.DataLayer/Shift.DataLayer.csproj
index 58095ea..80375ed 100644
--- a/Shift.DataLayer/Shift.DataLayer.csproj
+++ b/Shift.DataLayer/Shift.DataLayer.csproj
@@ -57,8 +57,8 @@
..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll
True
-
- ..\packages\StackExchange.Redis.1.2.4\lib\net46\StackExchange.Redis.dll
+
+ ..\packages\StackExchange.Redis.1.2.6\lib\net46\StackExchange.Redis.dll
True
diff --git a/Shift.DataLayer/packages.config b/Shift.DataLayer/packages.config
index 2bb9a88..af8248f 100644
--- a/Shift.DataLayer/packages.config
+++ b/Shift.DataLayer/packages.config
@@ -6,6 +6,6 @@
-
+
\ No newline at end of file
diff --git a/Shift.Entities/Properties/AssemblyInfo.cs b/Shift.Entities/Properties/AssemblyInfo.cs
index 70871b0..69be9c8 100644
--- a/Shift.Entities/Properties/AssemblyInfo.cs
+++ b/Shift.Entities/Properties/AssemblyInfo.cs
@@ -35,4 +35,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
diff --git a/Shift.UnitTest.DataLayer/Properties/AssemblyInfo.cs b/Shift.UnitTest.DataLayer/Properties/AssemblyInfo.cs
index 227cd87..f718157 100644
--- a/Shift.UnitTest.DataLayer/Properties/AssemblyInfo.cs
+++ b/Shift.UnitTest.DataLayer/Properties/AssemblyInfo.cs
@@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
diff --git a/Shift.UnitTest.DataLayer/Shift.UnitTest.DataLayer.csproj b/Shift.UnitTest.DataLayer/Shift.UnitTest.DataLayer.csproj
index 528eb07..d471f00 100644
--- a/Shift.UnitTest.DataLayer/Shift.UnitTest.DataLayer.csproj
+++ b/Shift.UnitTest.DataLayer/Shift.UnitTest.DataLayer.csproj
@@ -42,8 +42,8 @@
..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll
True
-
- ..\packages\Moq.4.7.63\lib\net45\Moq.dll
+
+ ..\packages\Moq.4.7.99\lib\net45\Moq.dll
True
diff --git a/Shift.UnitTest.DataLayer/packages.config b/Shift.UnitTest.DataLayer/packages.config
index d36b298..6131d65 100644
--- a/Shift.UnitTest.DataLayer/packages.config
+++ b/Shift.UnitTest.DataLayer/packages.config
@@ -1,7 +1,7 @@
-
+
diff --git a/Shift.UnitTest/JobClientRedisAsyncTest.cs b/Shift.UnitTest/JobClientRedisAsyncTest.cs
new file mode 100644
index 0000000..448e087
--- /dev/null
+++ b/Shift.UnitTest/JobClientRedisAsyncTest.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Configuration;
+using Xunit;
+using Shift.Entities;
+using Moq;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+
+namespace Shift.UnitTest
+{
+ public class JobClientRedisAsyncTest
+ {
+ JobClient jobClient;
+ private const string AppID = "TestAppID";
+
+ public JobClientRedisAsyncTest()
+ {
+ var appSettingsReader = new AppSettingsReader();
+
+ //Configure storage connection
+ var clientConfig = new ClientConfig();
+ clientConfig.DBConnectionString = appSettingsReader.GetValue("RedisConnectionString", typeof(string)) as string;
+ clientConfig.StorageMode = "redis";
+ jobClient = new JobClient(clientConfig);
+ }
+
+ [Fact]
+ public async Task GetJob_Valid()
+ {
+ var jobID = await jobClient.AddAsync(AppID, () => Console.WriteLine("Hello Test"));
+ var job = await jobClient.GetJobAsync(jobID);
+
+ await jobClient.DeleteJobsAsync(new List() { jobID });
+
+ Assert.NotNull(job);
+ Assert.Equal(jobID, job.JobID);
+ }
+ }
+}
diff --git a/Shift.UnitTest/JobClientRedisTest.cs b/Shift.UnitTest/JobClientRedisTest.cs
new file mode 100644
index 0000000..37f6a91
--- /dev/null
+++ b/Shift.UnitTest/JobClientRedisTest.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Configuration;
+using Xunit;
+using Shift.Entities;
+using Moq;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+
+namespace Shift.UnitTest
+{
+ public class JobClientRedisTest
+ {
+ JobClient jobClient;
+ private const string AppID = "TestAppID";
+
+ public JobClientRedisTest()
+ {
+ var appSettingsReader = new AppSettingsReader();
+
+ //Configure storage connection
+ var clientConfig = new ClientConfig();
+ clientConfig.DBConnectionString = appSettingsReader.GetValue("RedisConnectionString", typeof(string)) as string;
+ clientConfig.StorageMode = "redis";
+ jobClient = new JobClient(clientConfig);
+ }
+
+ [Fact]
+ public void GetJob_Valid()
+ {
+ var jobID = jobClient.Add(AppID, () => Console.WriteLine("Hello Test"));
+ var job = jobClient.GetJob(jobID);
+
+ jobClient.DeleteJobs(new List() { jobID });
+
+ Assert.NotNull(job);
+ Assert.Equal(jobID, job.JobID);
+ }
+ }
+}
diff --git a/Shift.UnitTest/Properties/AssemblyInfo.cs b/Shift.UnitTest/Properties/AssemblyInfo.cs
index d7df8d6..fcd89cb 100644
--- a/Shift.UnitTest/Properties/AssemblyInfo.cs
+++ b/Shift.UnitTest/Properties/AssemblyInfo.cs
@@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
diff --git a/Shift.UnitTest/Shift.UnitTest.csproj b/Shift.UnitTest/Shift.UnitTest.csproj
index c82fd59..176c18e 100644
--- a/Shift.UnitTest/Shift.UnitTest.csproj
+++ b/Shift.UnitTest/Shift.UnitTest.csproj
@@ -38,8 +38,8 @@
4
-
- ..\packages\Autofac.4.6.0\lib\net45\Autofac.dll
+
+ ..\packages\Autofac.4.6.1\lib\net45\Autofac.dll
True
@@ -49,8 +49,8 @@
False
-
- ..\packages\Moq.4.7.63\lib\net45\Moq.dll
+
+ ..\packages\Moq.4.7.99\lib\net45\Moq.dll
True
@@ -86,6 +86,8 @@
+
+
diff --git a/Shift.UnitTest/packages.config b/Shift.UnitTest/packages.config
index 6daea32..bcbb9e9 100644
--- a/Shift.UnitTest/packages.config
+++ b/Shift.UnitTest/packages.config
@@ -1,8 +1,8 @@
-
+
-
+
diff --git a/Shift/JobClient.cs b/Shift/JobClient.cs
index e3711b3..4ce1462 100644
--- a/Shift/JobClient.cs
+++ b/Shift/JobClient.cs
@@ -14,8 +14,6 @@ namespace Shift
public class JobClient
{
private IJobDAL jobDAL = null;
- private readonly ContainerBuilder builder;
- private readonly IContainer container;
///
/// Initializes a new instance of JobClient class, injects data layer with connection and configuration strings.
@@ -53,12 +51,15 @@ public JobClient(ClientConfig config)
throw new ArgumentNullException("Unable to run without Cache configuration string.");
}
- builder = new ContainerBuilder();
+ var builder = new ContainerBuilder();
builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.UseCache, config.CacheConfigurationString, config.EncryptionKey, config.DBAuthKey);
- container = builder.Build();
-
- jobDAL = container.Resolve();
+ var container = builder.Build();
+ //Use lifetime scope to avoid memory leak http://docs.autofac.org/en/latest/resolve/
+ using (var scope = container.BeginLifetimeScope())
+ {
+ jobDAL = container.Resolve();
+ }
}
public JobClient(IJobDAL jobDAL)
diff --git a/Shift/JobServer.cs b/Shift/JobServer.cs
index 9862b7f..240b24a 100644
--- a/Shift/JobServer.cs
+++ b/Shift/JobServer.cs
@@ -8,14 +8,13 @@
using Autofac;
using Autofac.Features.ResolveAnything;
+using Shift.Entities;
namespace Shift
{
public class JobServer
{
private ServerConfig config = null;
- private readonly ContainerBuilder builder;
- private readonly IContainer container;
private static System.Timers.Timer timer = null;
private static System.Timers.Timer timer2 = null;
@@ -61,21 +60,6 @@ public JobServer(ServerConfig config)
this.config = config;
- builder = new ContainerBuilder();
- builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
- RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.UseCache, config.CacheConfigurationString, config.EncryptionKey, config.DBAuthKey);
- container = builder.Build();
-
- Initialize();
- }
-
- #region Startup
- ///
- /// Instantiate the data layer and loads all the referenced assemblies defined in the assembly list text file
- /// in Options.AssemblyListPath and Options.AssemblyBaseDir
- ///
- private void Initialize()
- {
this.workerList = new List();
//OPTIONAL: Load all EXTERNAL DLLs needed by this process
@@ -83,15 +67,22 @@ private void Initialize()
AssemblyHelpers.LoadAssemblies(config.AssemblyFolder, config.AssemblyListPath);
//Create Worker
- for(var i=1; i <= config.Workers; i++)
+ var builder = new ContainerBuilder();
+ builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
+ RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.UseCache, config.CacheConfigurationString, config.EncryptionKey, config.DBAuthKey);
+ var container = builder.Build();
+ //Use lifetime scope to avoid memory leak http://docs.autofac.org/en/latest/resolve/
+ using (var scope = container.BeginLifetimeScope())
{
- var worker = new Worker(config, container, i);
- workerList.Add(worker);
+ var jobDAL = scope.Resolve();
+ for (var i = 1; i <= config.Workers; i++)
+ {
+ var worker = new Worker(config, jobDAL, i);
+ workerList.Add(worker);
+ }
}
}
- #endregion
-
#region Server Run and Manage jobs
///
diff --git a/Shift/Properties/AssemblyInfo.cs b/Shift/Properties/AssemblyInfo.cs
index 0fef457..df300b5 100644
--- a/Shift/Properties/AssemblyInfo.cs
+++ b/Shift/Properties/AssemblyInfo.cs
@@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
diff --git a/Shift/Shift.csproj b/Shift/Shift.csproj
index 23ae4cb..b0aa579 100644
--- a/Shift/Shift.csproj
+++ b/Shift/Shift.csproj
@@ -34,8 +34,8 @@
bin\Release\Shift.XML
-
- ..\packages\Autofac.4.6.0\lib\net45\Autofac.dll
+
+ ..\packages\Autofac.4.6.1\lib\net45\Autofac.dll
True
diff --git a/Shift/Worker.cs b/Shift/Worker.cs
index e1829d2..145620d 100644
--- a/Shift/Worker.cs
+++ b/Shift/Worker.cs
@@ -26,10 +26,10 @@ public class Worker
private int? autoDeletePeriod;
private IList autoDeleteStatus;
- public Worker(ServerConfig config, IContainer container, int workerID)
+ public Worker(ServerConfig config, IJobDAL jobDAL, int workerID)
{
taskList = new Dictionary();
- jobDAL = container.Resolve();
+ this.jobDAL = jobDAL;
this.workerID = workerID;
this.workerProcessID = config.ProcessID + "-" + workerID;
diff --git a/Shift/packages.config b/Shift/packages.config
index 0767704..dcf6f12 100644
--- a/Shift/packages.config
+++ b/Shift/packages.config
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file