From 02bca91eb2c8119a33ac8b93a08b35a6db132312 Mon Sep 17 00:00:00 2001 From: vk Date: Sat, 16 Jul 2016 15:30:24 -0400 Subject: [PATCH] Wrong scheduler factory was used, fixes #26 Decrease scope tracking logging level. --- CONTRIBUTING.md | 4 ++ appveyor.yml | 2 +- build.proj | 4 +- src/Autofac.Extras.Quartz.sln.DotSettings | 2 + .../Autofac.Extras.Quartz.csproj | 4 +- .../Autofac.Extras.Quartz.nuspec | 3 +- .../AutofacJobFactory.cs | 22 +++++---- .../AutofacSchedulerFactory.cs | 2 +- .../Properties/AssemblyInfo.cs | 13 +++--- .../QuartzAutofacFactoryModule.cs | 5 +- .../QuartzAutofacJobsModule.cs | 3 +- src/Autofac.Extras.Quartz/packages.config | 2 +- src/Samples/SimpleService/App.config | 13 +++--- src/Samples/SimpleService/Program.cs | 46 +++++++++++-------- src/Tests/Tests.csproj | 32 +++++++------ src/Tests/app.config | 4 +- src/Tests/packages.config | 15 +++--- 17 files changed, 100 insertions(+), 76 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..206d631 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +#Contributing# + +##Dependencies upgrade## +When NUnit.ConsoleRunner is upgraded make sure build.proj/Test target has correct path to the nunit.console. diff --git a/appveyor.yml b/appveyor.yml index 435df6f..ff0f2a2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.1.0-beta-{build} +version: 2.1.1.{build} clone_depth: 3 clone_folder: c:\work\autofac.extras.quartz pull_requests: diff --git a/build.proj b/build.proj index be234b6..9c69c48 100644 --- a/build.proj +++ b/build.proj @@ -1,5 +1,5 @@ - + Rebuild @@ -46,7 +46,7 @@ diff --git a/src/Autofac.Extras.Quartz.sln.DotSettings b/src/Autofac.Extras.Quartz.sln.DotSettings index 22a349c..4bcf0d8 100644 --- a/src/Autofac.Extras.Quartz.sln.DotSettings +++ b/src/Autofac.Extras.Quartz.sln.DotSettings @@ -2,7 +2,9 @@ DO_NOT_SHOW <?xml version="1.0" encoding="utf-16"?><Profile name="Full"><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUseVar><BehavourStyle>CAN_CHANGE_TO_IMPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_EXCEPT_PRIMITIVE_TYPES</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSReorderTypeMembers>True</CSReorderTypeMembers><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><VBReformatCode>True</VBReformatCode><VBFormatDocComments>True</VBFormatDocComments><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><CssAlphabetizeProperties>True</CssAlphabetizeProperties><CssReformatCode>True</CssReformatCode><XMLReformatCode>True</XMLReformatCode><CSUpdateFileHeader>True</CSUpdateFileHeader></Profile> False + END_OF_LINE END_OF_LINE + END_OF_LINE True True copyright diff --git a/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.csproj b/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.csproj index e7f5655..aa38c5a 100644 --- a/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.csproj +++ b/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.csproj @@ -52,8 +52,8 @@ ..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll True - - ..\packages\JetBrains.Annotations.10.0.0\lib\net20\JetBrains.Annotations.dll + + ..\packages\JetBrains.Annotations.10.1.5\lib\net\JetBrains.Annotations.dll True diff --git a/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.nuspec b/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.nuspec index fa8afeb..6582d67 100644 --- a/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.nuspec +++ b/src/Autofac.Extras.Quartz/Autofac.Extras.Quartz.nuspec @@ -11,7 +11,8 @@ false $description$ -Optional dependencies support. +Decrease scope tracking log level to Trace. +Upgrade depdencies. Copyright 2014-2016 alphacloud quartz autofac diff --git a/src/Autofac.Extras.Quartz/AutofacJobFactory.cs b/src/Autofac.Extras.Quartz/AutofacJobFactory.cs index 5579125..6f91349 100644 --- a/src/Autofac.Extras.Quartz/AutofacJobFactory.cs +++ b/src/Autofac.Extras.Quartz/AutofacJobFactory.cs @@ -3,7 +3,7 @@ // Autofac Quartz integration // https://github.com/alphacloud/Autofac.Extras.Quartz // Licensed under MIT license. -// Copyright (c) 2014-2015 Alphacloud.Net +// Copyright (c) 2014-2016 Alphacloud.Net #endregion @@ -86,9 +86,12 @@ public void Dispose() /// /// the newly instantiated Job /// - /// is . - /// is . - /// Error resolving exception. Original exception will be stored in . + /// is . + /// is . + /// + /// Error resolving exception. Original exception will be stored in + /// . + /// [NotNull] public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { @@ -106,9 +109,9 @@ public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) var jobTrackingInfo = new JobTrackingInfo(nestedScope); RunningJobs[newJob] = jobTrackingInfo; - if (s_log.IsDebugEnabled) + if (s_log.IsTraceEnabled) { - s_log.DebugFormat(CultureInfo.InvariantCulture, "Scope 0x{0:x} associated with Job 0x{1:x}", + s_log.TraceFormat(CultureInfo.InvariantCulture, "Scope 0x{0:x} associated with Job 0x{1:x}", jobTrackingInfo.Scope.GetHashCode(), newJob.GetHashCode()); } @@ -139,6 +142,7 @@ public void ReturnJob([CanBeNull] IJob job) if (!RunningJobs.TryRemove(job, out trackingInfo)) { s_log.WarnFormat("Tracking info for job 0x{0:x} not found", job.GetHashCode()); + // ReSharper disable once SuspiciousTypeConversion.Global var disposableJob = job as IDisposable; disposableJob?.Dispose(); } @@ -150,16 +154,16 @@ public void ReturnJob([CanBeNull] IJob job) static void DisposeScope(IJob job, ILifetimeScope lifetimeScope) { - if (s_log.IsDebugEnabled) + if (s_log.IsTraceEnabled) { - s_log.DebugFormat("Disposing Scope 0x{0:x} for Job 0x{1:x}", + s_log.TraceFormat("Disposing Scope 0x{0:x} for Job 0x{1:x}", lifetimeScope?.GetHashCode() ?? 0, job?.GetHashCode() ?? 0); } lifetimeScope?.Dispose(); } - #region Job data + #region Job data internal sealed class JobTrackingInfo { diff --git a/src/Autofac.Extras.Quartz/AutofacSchedulerFactory.cs b/src/Autofac.Extras.Quartz/AutofacSchedulerFactory.cs index 7e39392..d448726 100644 --- a/src/Autofac.Extras.Quartz/AutofacSchedulerFactory.cs +++ b/src/Autofac.Extras.Quartz/AutofacSchedulerFactory.cs @@ -3,7 +3,7 @@ // Autofac Quartz integration // https://github.com/alphacloud/Autofac.Extras.Quartz // Licensed under MIT license. -// Copyright (c) 2014-2015 Alphacloud.Net +// Copyright (c) 2014-2016 Alphacloud.Net #endregion diff --git a/src/Autofac.Extras.Quartz/Properties/AssemblyInfo.cs b/src/Autofac.Extras.Quartz/Properties/AssemblyInfo.cs index c9a9e6d..cf319b6 100644 --- a/src/Autofac.Extras.Quartz/Properties/AssemblyInfo.cs +++ b/src/Autofac.Extras.Quartz/Properties/AssemblyInfo.cs @@ -3,7 +3,7 @@ // Autofac Quartz integration // https://github.com/alphacloud/Autofac.Extras.Quartz // Licensed under MIT license. -// Copyright (c) 2014-2015 Alphacloud.Net +// Copyright (c) 2014-2016 Alphacloud.Net #endregion @@ -11,7 +11,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. @@ -24,8 +24,8 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] @@ -33,8 +33,9 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("b7307028-45b4-495c-8c38-8a60dbef8aca")] -[assembly: AssemblyVersion("2.1.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.1.0")] +[assembly: AssemblyFileVersion("2.1.1.0")] +[assembly: AssemblyInformationalVersion("2.1.1.0")] [assembly: InternalsVisibleTo("Autofac.Extras.Quartz.Tests, PublicKey=" + "00240000048000009400000006020000002400005253413100040000010001003b6b2a7202e9a5" + "c9b62e49f9f05bebbfd23fc6f08f0ec853d0857fc6cd3ca06d524c96651f82c6cddec44b9c0a20" diff --git a/src/Autofac.Extras.Quartz/QuartzAutofacFactoryModule.cs b/src/Autofac.Extras.Quartz/QuartzAutofacFactoryModule.cs index 697ee25..b9bf732 100644 --- a/src/Autofac.Extras.Quartz/QuartzAutofacFactoryModule.cs +++ b/src/Autofac.Extras.Quartz/QuartzAutofacFactoryModule.cs @@ -3,7 +3,7 @@ // Autofac Quartz integration // https://github.com/alphacloud/Autofac.Extras.Quartz // Licensed under MIT license. -// Copyright (c) 2014-2015 Alphacloud.Net +// Copyright (c) 2014-2016 Alphacloud.Net #endregion @@ -76,8 +76,7 @@ protected override void Load([NotNull] ContainerBuilder builder) .As() .SingleInstance(); - builder.Register(c => - { + builder.Register(c => { var cfgProvider = ConfigurationProvider; var autofacSchedulerFactory = cfgProvider != null diff --git a/src/Autofac.Extras.Quartz/QuartzAutofacJobsModule.cs b/src/Autofac.Extras.Quartz/QuartzAutofacJobsModule.cs index d6df678..4f3297b 100644 --- a/src/Autofac.Extras.Quartz/QuartzAutofacJobsModule.cs +++ b/src/Autofac.Extras.Quartz/QuartzAutofacJobsModule.cs @@ -11,6 +11,7 @@ namespace Autofac.Extras.Quartz { using System; using System.Reflection; + using Core; using global::Quartz; using JetBrains.Annotations; using Module = Autofac.Module; @@ -65,7 +66,7 @@ public QuartzAutofacJobsModule([NotNull] params Assembly[] assembliesToScan) protected override void Load(ContainerBuilder builder) { var registrationBuilder = builder.RegisterAssemblyTypes(_assembliesToScan) - .Where(type => !type.IsAbstract && typeof (IJob).IsAssignableFrom(type)) + .Where(type => !type.IsAbstract && typeof(IJob).IsAssignableFrom(type)) .AsSelf().InstancePerLifetimeScope(); if (AutoWireProperties) diff --git a/src/Autofac.Extras.Quartz/packages.config b/src/Autofac.Extras.Quartz/packages.config index 83f2dbe..7807708 100644 --- a/src/Autofac.Extras.Quartz/packages.config +++ b/src/Autofac.Extras.Quartz/packages.config @@ -3,6 +3,6 @@ - + \ No newline at end of file diff --git a/src/Samples/SimpleService/App.config b/src/Samples/SimpleService/App.config index 8e49dac..7aa77fe 100644 --- a/src/Samples/SimpleService/App.config +++ b/src/Samples/SimpleService/App.config @@ -1,4 +1,5 @@  +
@@ -8,7 +9,7 @@ - + @@ -32,6 +33,10 @@ + + + + @@ -41,7 +46,7 @@ - + @@ -56,10 +61,6 @@ - - - - diff --git a/src/Samples/SimpleService/Program.cs b/src/Samples/SimpleService/Program.cs index 974759b..c4fc2c4 100644 --- a/src/Samples/SimpleService/Program.cs +++ b/src/Samples/SimpleService/Program.cs @@ -3,20 +3,20 @@ // Autofac Quartz integration // https://github.com/alphacloud/Autofac.Extras.Quartz // Licensed under MIT license. -// Copyright (c) 2015 Alphacloud.Net +// Copyright (c) 2014-2016 Alphacloud.Net #endregion namespace SimpleService { using System; + using System.Collections.Specialized; using AppServices; using Autofac; using Autofac.Extras.Quartz; using Common.Logging; using Jobs; using Quartz; - using Quartz.Spi; using Topshelf; using Topshelf.Autofac; using Topshelf.Quartz; @@ -24,10 +24,10 @@ namespace SimpleService internal static class Program { - private static readonly ILog s_log = LogManager.GetLogger(typeof (Program)); - private static IContainer _container; + static readonly ILog s_log = LogManager.GetLogger(typeof(Program)); + static IContainer _container; - private static int Main(string[] args) + static int Main(string[] args) { Console.WriteLine("This sample demostrates how to integrate Quartz, TopShelf and Autofac."); s_log.Info("Starting..."); @@ -35,23 +35,22 @@ private static int Main(string[] args) { _container = ConfigureContainer(new ContainerBuilder()).Build(); - HostFactory.Run(conf => - { + ScheduleJobServiceConfiguratorExtensions.SchedulerFactory = () => _container.Resolve(); + + HostFactory.Run(conf => { conf.SetServiceName("AutofacExtras.Quartz.Sample"); - conf.SetDisplayName("Quartz.Net integration for autofac"); + conf.SetDisplayName("Quartz.Net integration for Autofac"); conf.UseLog4Net(); conf.UseAutofacContainer(_container); - conf.Service(svc => - { + conf.Service(svc => { svc.ConstructUsingAutofacContainer(); svc.WhenStarted(o => o.Start()); - svc.WhenStopped(o => - { + svc.WhenStopped(o => { o.Stop(); _container.Dispose(); }); - ConfigureBackgroundJobs(svc); + ConfigureScheduler(svc); }); }); @@ -68,12 +67,10 @@ private static int Main(string[] args) } } - private static void ConfigureBackgroundJobs(ServiceConfigurator svc) + static void ConfigureScheduler(ServiceConfigurator svc) { - svc.UsingQuartzJobFactory(() => _container.Resolve()); - - svc.ScheduleQuartzJob(q => - { + svc.ScheduleQuartzJob(q => { + s_log.Trace("Configuring jobs"); q.WithJob(JobBuilder.Create() .WithIdentity("Heartbeat", "Maintenance") .Build); @@ -84,8 +81,17 @@ private static void ConfigureBackgroundJobs(ServiceConfigurator svc internal static ContainerBuilder ConfigureContainer(ContainerBuilder cb) { - cb.RegisterModule(new QuartzAutofacFactoryModule()); - cb.RegisterModule(new QuartzAutofacJobsModule(typeof (HeartbeatJob).Assembly)); + // configure and register Quartz + var schedulerConfig = new NameValueCollection { + {"quartz.threadPool.threadCount", "3"}, + {"quartz.threadPool.threadNamePrefix", "SchedulerWorker"}, + {"quartz.scheduler.threadName", "Scheduler"} + }; + + cb.RegisterModule(new QuartzAutofacFactoryModule { + ConfigurationProvider = c => schedulerConfig + }); + cb.RegisterModule(new QuartzAutofacJobsModule(typeof(HeartbeatJob).Assembly)); RegisterComponents(cb); return cb; diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 82bc0a0..7711325 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -46,16 +46,20 @@ ..\keyfile.snk - - ..\packages\Alphacloud.Common.Testing.Nunit.0.3.3.0\lib\net45\Alphacloud.Common.Testing.Nunit.dll + + ..\packages\Alphacloud.Common.Testing.Nunit.0.6.0.0\lib\net45\Alphacloud.Common.Testing.Nunit.dll True False ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll - - ..\packages\AutoMapper.4.2.1\lib\net45\AutoMapper.dll + + ..\packages\AutoMapper.5.0.2\lib\net45\AutoMapper.dll + True + + + ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True @@ -66,25 +70,25 @@ ..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll True - - ..\packages\FluentAssertions.4.3.2\lib\net45\FluentAssertions.dll + + ..\packages\FluentAssertions.4.12.0\lib\net45\FluentAssertions.dll True - - ..\packages\FluentAssertions.4.3.2\lib\net45\FluentAssertions.Core.dll + + ..\packages\FluentAssertions.4.12.0\lib\net45\FluentAssertions.Core.dll True - - ..\packages\JetBrains.Annotations.10.0.0\lib\net20\JetBrains.Annotations.dll + + ..\packages\JetBrains.Annotations.10.1.5\lib\net\JetBrains.Annotations.dll True - - ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll + + ..\packages\Moq.4.5.13\lib\net45\Moq.dll True - - ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll + + ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll True diff --git a/src/Tests/app.config b/src/Tests/app.config index af6efb9..873013b 100644 --- a/src/Tests/app.config +++ b/src/Tests/app.config @@ -9,11 +9,11 @@ - + - + diff --git a/src/Tests/packages.config b/src/Tests/packages.config index 6eb80df..54f96b0 100644 --- a/src/Tests/packages.config +++ b/src/Tests/packages.config @@ -1,14 +1,15 @@  - + - + + - - - - - + + + + + \ No newline at end of file