Skip to content

Commit 63a810d

Browse files
committed
Merge branch 'feature/9' into develop
2 parents 5dfff32 + c2bc838 commit 63a810d

File tree

17 files changed

+268
-133
lines changed

17 files changed

+268
-133
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454

5555
| Package | Dependencies | Target Framework | Documentation |
5656
| :------ | :------: | :------: | :------: |
57-
| [![Simplify.Scheduler](http://img.shields.io/badge/Simplify.Scheduler-v1.0-blue.svg)](https://www.nuget.org/packages/Simplify.Scheduler/) ![prerelease](https://img.shields.io/badge/prerelease-v02-red)| [![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/nuget/Simplify.Scheduler.svg)](https://libraries.io/nuget/Simplify.Scheduler) | Standard 2.0 | [![Documentation](https://img.shields.io/badge/docs-green.svg)](https://github.com/SimplifyNet/Simplify/wiki/Simplify.Scheduler) |
58-
| [![Simplify.WindowsServices](http://img.shields.io/badge/Simplify.WindowsServices-v2.9.1-blue.svg)](https://www.nuget.org/packages/Simplify.WindowsServices/) | [![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/nuget/Simplify.WindowsServices.svg)](https://libraries.io/nuget/Simplify.WindowsServices) | 4.6.2 | [![Documentation](https://img.shields.io/badge/docs-green.svg)](https://github.com/SimplifyNet/Simplify/wiki/Simplify.WindowsServices) |
57+
| [![Simplify.Scheduler](http://img.shields.io/badge/Simplify.Scheduler-v1.0-blue.svg)](https://www.nuget.org/packages/Simplify.Scheduler/) ![prerelease](https://img.shields.io/badge/prerelease-v03-red)| [![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/nuget/Simplify.Scheduler.svg)](https://libraries.io/nuget/Simplify.Scheduler) | Standard 2.0 | [![Documentation](https://img.shields.io/badge/docs-green.svg)](https://github.com/SimplifyNet/Simplify/wiki/Simplify.Scheduler) |
58+
| [![Simplify.WindowsServices](http://img.shields.io/badge/Simplify.WindowsServices-v2.10-blue.svg)](https://www.nuget.org/packages/Simplify.WindowsServices/) | [![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/nuget/Simplify.WindowsServices.svg)](https://libraries.io/nuget/Simplify.WindowsServices) | 4.6.2 | [![Documentation](https://img.shields.io/badge/docs-green.svg)](https://github.com/SimplifyNet/Simplify/wiki/Simplify.WindowsServices) |
5959

6060
### Main
6161

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: '{build}'
22

3-
image: Visual Studio 2017
3+
image: Visual Studio 2019
44

55
skip_tags: true
66
clone_depth: 1

src/Simplify.Scheduler.IntegrationTester/Program.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Simplify.DI;
1+
using System;
2+
using Simplify.DI;
23
using Simplify.Scheduler.IntegrationTester.Setup;
34

45
namespace Simplify.Scheduler.IntegrationTester
@@ -16,6 +17,9 @@ private static void Main(string[] args)
1617

1718
using (var scheduler = new MultitaskScheduler())
1819
{
20+
scheduler.OnJobStart += HandlerOnJobStart;
21+
scheduler.OnJobFinish += HandlerOnJobFinish;
22+
1923
scheduler.AddJob<OneSecondStepProcessor>(IocRegistrations.Configuration);
2024
scheduler.AddJob<TwoSecondStepProcessor>(IocRegistrations.Configuration, startupArgs: "Hello world!!!");
2125
scheduler.AddJob<OneMinuteStepCrontabProcessor>(IocRegistrations.Configuration);
@@ -30,5 +34,15 @@ private static void Main(string[] args)
3034
using (var scope = DIContainer.Current.BeginLifetimeScope())
3135
scope.Resolver.Resolve<BasicTaskProcessor>().Run();
3236
}
37+
38+
private static void HandlerOnJobStart(Jobs.ISchedulerJobRepresentation representation)
39+
{
40+
Console.WriteLine("Job started: " + representation.JobClassType.Name);
41+
}
42+
43+
private static void HandlerOnJobFinish(Jobs.ISchedulerJobRepresentation representation)
44+
{
45+
Console.WriteLine("Job finished: " + representation.JobClassType.Name);
46+
}
3347
}
3448
}

src/Simplify.Scheduler/Jobs/Crontab/CrontabProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using NCrontab;
2-
using Simplify.System;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.Linq;
4+
using NCrontab;
5+
using Simplify.System;
66

77
namespace Simplify.Scheduler.Jobs.Crontab
88
{

src/Simplify.Scheduler/Jobs/ISchedulerJob.cs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,10 @@
1-
using System;
2-
using System.Reflection;
3-
41
namespace Simplify.Scheduler.Jobs
52
{
63
/// <summary>
74
/// Represent basic scheduler job
85
/// </summary>
9-
public interface ISchedulerJob
6+
public interface ISchedulerJob : ISchedulerJobRepresentation
107
{
11-
/// <summary>
12-
/// Gets the type of the job class.
13-
/// </summary>
14-
/// <value>
15-
/// The type of the job class.
16-
/// </value>
17-
Type JobClassType { get; }
18-
19-
/// <summary>
20-
/// Gets the invoke method information.
21-
/// </summary>
22-
/// <value>
23-
/// The invoke method information.
24-
/// </value>
25-
MethodInfo InvokeMethodInfo { get; }
26-
27-
/// <summary>
28-
/// Gets the type of the invoke method parameter.
29-
/// </summary>
30-
/// <value>
31-
/// The type of the invoke method parameter.
32-
/// </value>
33-
InvokeMethodParameterType InvokeMethodParameterType { get; }
34-
35-
/// <summary>
36-
/// Gets the job arguments.
37-
/// </summary>
38-
/// <value>
39-
/// The job arguments.
40-
/// </value>
41-
IJobArgs JobArgs { get; }
42-
438
/// <summary>
449
/// Starts this job timer.
4510
/// </summary>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Reflection;
3+
4+
namespace Simplify.Scheduler.Jobs
5+
{
6+
/// <summary>
7+
/// Represent scheduler job information and args
8+
/// </summary>
9+
public interface ISchedulerJobRepresentation
10+
{
11+
/// <summary>
12+
/// Gets the type of the job class.
13+
/// </summary>
14+
/// <value>
15+
/// The type of the job class.
16+
/// </value>
17+
Type JobClassType { get; }
18+
19+
/// <summary>
20+
/// Gets the invoke method information.
21+
/// </summary>
22+
/// <value>
23+
/// The invoke method information.
24+
/// </value>
25+
MethodInfo InvokeMethodInfo { get; }
26+
27+
/// <summary>
28+
/// Gets the type of the invoke method parameter.
29+
/// </summary>
30+
/// <value>
31+
/// The type of the invoke method parameter.
32+
/// </value>
33+
InvokeMethodParameterType InvokeMethodParameterType { get; }
34+
35+
/// <summary>
36+
/// Gets the job arguments.
37+
/// </summary>
38+
/// <value>
39+
/// The job arguments.
40+
/// </value>
41+
IJobArgs JobArgs { get; }
42+
}
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Simplify.Scheduler.Jobs
2+
{
3+
/// <summary>
4+
/// Represent job related events handler
5+
/// </summary>
6+
/// <param name="representation">The representation.</param>
7+
public delegate void JobEventHandler(ISchedulerJobRepresentation representation);
8+
}

src/Simplify.Scheduler/SchedulerJobsHandler.cs

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using Microsoft.Extensions.Configuration;
2-
using Simplify.DI;
3-
using Simplify.Scheduler.Jobs;
4-
using Simplify.Scheduler.Jobs.Crontab;
5-
using Simplify.System;
6-
using System;
1+
using System;
72
using System.Collections.Generic;
83
using System.Linq;
94
using System.Reflection;
105
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Configuration;
7+
using Simplify.DI;
8+
using Simplify.Scheduler.Jobs;
9+
using Simplify.Scheduler.Jobs.Crontab;
10+
using Simplify.System;
1111

1212
namespace Simplify.Scheduler
1313
{
@@ -18,7 +18,7 @@ public abstract class SchedulerJobsHandler : IDisposable
1818
{
1919
private readonly IList<ISchedulerJob> _jobs = new List<ISchedulerJob>();
2020
private readonly IList<ICrontabSchedulerJobTask> _workingJobsTasks = new List<ICrontabSchedulerJobTask>();
21-
private readonly IDictionary<object, ILifetimeScope> _workingBasicJobs = new Dictionary<object, ILifetimeScope>();
21+
private readonly IDictionary<ISchedulerJobRepresentation, ILifetimeScope> _workingBasicJobs = new Dictionary<ISchedulerJobRepresentation, ILifetimeScope>();
2222

2323
private long _jobTaskID;
2424
private bool _shutdownInProcess;
@@ -39,6 +39,16 @@ protected SchedulerJobsHandler()
3939
/// </summary>
4040
public event SchedulerExceptionEventHandler OnException;
4141

42+
/// <summary>
43+
/// Occurs when the job start.
44+
/// </summary>
45+
public event JobEventHandler OnJobStart;
46+
47+
/// <summary>
48+
/// Occurs when job is finished.
49+
/// </summary>
50+
public event JobEventHandler OnJobFinish;
51+
4252
/// <summary>
4353
/// Gets the name of the application.
4454
/// </summary>
@@ -148,7 +158,11 @@ protected virtual void Dispose(bool disposing)
148158
{
149159
if (disposing)
150160
foreach (var basicJobItem in _workingBasicJobs)
161+
{
162+
OnJobFinish?.Invoke(basicJobItem.Key);
163+
151164
basicJobItem.Value.Dispose();
165+
}
152166
}
153167

154168
private void InitializeJob(ICrontabSchedulerJob job)
@@ -187,13 +201,15 @@ private void OnStartWork(object state)
187201
}
188202
}
189203

204+
#region Execution
205+
190206
private void Run(object state)
191207
{
192208
var (jobTaskID, job) = (Tuple<long, ICrontabSchedulerJob>)state;
193209

194210
try
195211
{
196-
RunJob(job);
212+
RunScoped(job);
197213
}
198214
catch (Exception e)
199215
{
@@ -204,35 +220,37 @@ private void Run(object state)
204220
}
205221
finally
206222
{
207-
if (job.Settings.CleanupOnTaskFinish)
208-
GC.Collect();
209-
210-
lock (_workingJobsTasks)
211-
_workingJobsTasks.Remove(_workingJobsTasks.Single(x => x.ID == jobTaskID));
223+
FinalizeJob(jobTaskID, job);
212224
}
213225
}
214226

215-
private void RunJob(ISchedulerJob job)
227+
private void RunScoped(ISchedulerJobRepresentation job)
216228
{
217229
using (var scope = DIContainer.Current.BeginLifetimeScope())
218230
{
219231
var jobObject = scope.Resolver.Resolve(job.JobClassType);
220232

233+
OnJobStart?.Invoke(job);
234+
221235
InvokeJobMethod(job, jobObject);
236+
237+
OnJobFinish?.Invoke(job);
222238
}
223239
}
224240

225-
private void RunBasicJob(ISchedulerJob job)
241+
private void RunBasicJob(ISchedulerJobRepresentation job)
226242
{
227243
try
228244
{
229245
var scope = DIContainer.Current.BeginLifetimeScope();
230246

231247
var jobObject = scope.Resolver.Resolve(job.JobClassType);
232248

249+
OnJobStart?.Invoke(job);
250+
233251
InvokeJobMethod(job, jobObject);
234252

235-
_workingBasicJobs.Add(jobObject, scope);
253+
_workingBasicJobs.Add(job, scope);
236254
}
237255
catch (Exception e)
238256
{
@@ -243,7 +261,7 @@ private void RunBasicJob(ISchedulerJob job)
243261
}
244262
}
245263

246-
private void InvokeJobMethod(ISchedulerJob job, object jobObject)
264+
private void InvokeJobMethod(ISchedulerJobRepresentation job, object jobObject)
247265
{
248266
switch (job.InvokeMethodParameterType)
249267
{
@@ -263,5 +281,16 @@ private void InvokeJobMethod(ISchedulerJob job, object jobObject)
263281
throw new ArgumentOutOfRangeException();
264282
}
265283
}
284+
285+
private void FinalizeJob(long jobTaskID, ICrontabSchedulerJob job)
286+
{
287+
if (job.Settings.CleanupOnTaskFinish)
288+
GC.Collect();
289+
290+
lock (_workingJobsTasks)
291+
_workingJobsTasks.Remove(_workingJobsTasks.Single(x => x.ID == jobTaskID));
292+
}
293+
294+
#endregion Execution
266295
}
267296
}

src/Simplify.Scheduler/Simplify.Scheduler.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
<Product>Simplify</Product>
66
<Description>Scheduler framework with DI</Description>
77
<Copyright>Licensed under LGPL</Copyright>
8-
<Version>1.0-pre02</Version>
8+
<Version>1.0-pre03</Version>
99
<PackageProjectUrl>https://github.com/i4004/Simplify/wiki/Simplify.Scheduler</PackageProjectUrl>
1010
<PackageIconUrl>https://raw.githubusercontent.com/i4004/Simplify/master/Images/Icon.png</PackageIconUrl>
1111
<RepositoryUrl>https://github.com/i4004/Simplify/tree/master/src/Simplify.Scheduler</RepositoryUrl>
1212
<RepositoryType>GIT</RepositoryType>
1313
<PackageTags>.NET Scheduler DI</PackageTags>
1414
<PackageReleaseNotes>
15-
* Upgrade to Simplify.DI 3.0
15+
Updates
16+
* Upgrade to Simplify.DI 4.0
17+
* Upgrade to Simplify.System 1.2
18+
New Features
19+
* Scheduler OnStartJob/OnFinishJob events
1620
</PackageReleaseNotes>
1721
<OutputPath>bin\Any CPU\$(Configuration)\</OutputPath>
1822
<DocumentationFile>bin\Any CPU\$(Configuration)\$(TargetFramework)\Simplify.Scheduler.xml</DocumentationFile>
1923
</PropertyGroup>
2024
<ItemGroup>
2125
<PackageReference Include="ncrontab" Version="3.3.1" />
22-
<PackageReference Include="Simplify.DI" Version="3.0.0" />
23-
<PackageReference Include="Simplify.System" Version="1.1.0" />
26+
<PackageReference Include="Simplify.DI" Version="4.0.0" />
27+
<PackageReference Include="Simplify.System" Version="1.2.0" />
2428
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
2529
</ItemGroup>
2630
</Project>

src/Simplify.WindowsServices.IntegrationTester/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
4-
<section name="TaskProcessor1Settings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
5-
<section name="TaskProcessor4Settings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
4+
<section name="OneSecondStepProcessorSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
5+
<section name="TwoParallelTasksProcessorSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
66
</configSections>
77

88
<startup>

0 commit comments

Comments
 (0)