Skip to content

Commit 2e11249

Browse files
authored
Merge pull request #45 from kdcllc/feature/upgrade-deps
Feature/upgrade deps
2 parents 09450a4 + 7f33c02 commit 2e11249

20 files changed

+180
-28
lines changed

.github/FUNDING.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: [kdcllc]
4+
custom: ["https://www.buymeacoffee.com/vyve0og"]

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Change Log
33
===============================================================================
44

5+
Version 3.0.1
6+
* Fixed issue with Scheduled jobs that are added on the fly to the execution engine issue #43
7+
* Upgraded to the latest nuget packages
8+
59
Version 3.0.0
610

711
* Removed ScheduledJob class

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
![Nuget](https://img.shields.io/nuget/dt/CronScheduler.AspNetCore)
66
[![feedz.io](https://img.shields.io/badge/endpoint.svg?url=https://f.feedz.io/kdcllc/cronscheduler-aspnetcore/shield/CronScheduler.AspNetCore/latest)](https://f.feedz.io/kdcllc/cronscheduler-aspnetcore/packages/CronScheduler.AspNetCore/latest/download)
77

8+
*Note: Pre-release packages are distributed via [feedz.io](https://f.feedz.io/kdcllc/cronscheduler-aspnetcore/nuget/index.json).*
9+
10+
## Summary
11+
812
The goal of this library was to design a simple Cron Scheduling engine that could be used with DotNetCore `IHost` or with AspNetCore `IWebHost`.
913

1014
It is much lighter than Quartz schedular or its alternatives. In the heart of its design was `KISS` principle.
@@ -48,6 +52,12 @@ Cron expression is a mask to define fixed times, dates and intervals. The mask c
4852
│ │ │ │ │ │
4953
* * * * * *
5054

55+
[![buymeacoffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/vyve0og)
56+
57+
## Give a Star! :star:
58+
59+
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
60+
5161
## Demo Applications
5262

5363
- [CronSchedulerWorker](./src/CronSchedulerWorker/) - this example demonstrates how to use `CronScheduler` with new Microsoft .NET Core Workers Template

appveyor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ branches:
55
pull_requests:
66
do_not_increment_build_number: true
77
image: Visual Studio 2017
8-
## temporary until 3.1.101 sdk is installed
8+
## temporary until 5.0.100 sdk is installed
99
install:
10-
- ps: $urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/3.1.101/dotnet-sdk-3.1.101-win-x64.zip"
10+
- ps: $urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/5.0.100/dotnet-sdk-5.0.100-win-x64.zip"
1111
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
1212
- ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
1313
- ps: $tempFileCurrent = [System.IO.Path]::GetTempFileName()
@@ -33,6 +33,6 @@ deploy:
3333
- provider: NuGet
3434
artifact: /NuGet/
3535
api_key:
36-
secure: jrexooMHJwdbj5MGacSL9fCj3g2haDXMarPEkiLpdIZmasb/zeMYb0NVofvi5HvJ
36+
secure: hs4f+3xdpI1ANqvOB7J9BZx+aBdbZYzHmoYymDFA7YCt5AWLJSdNyv2nkrBn1V9q
3737
on:
3838
branch: master

build/dependencies.props

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
<AspNetCoreVersion>2.1.1</AspNetCoreVersion>
55
<ExtensionsVersion>2.1.1</ExtensionsVersion>
66
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
7-
<BetCommon>3.1.2</BetCommon>
7+
<BetCommon>3.1.11</BetCommon>
8+
</PropertyGroup>
9+
10+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'net5.0'">
11+
<AspNetCoreVersion>5.0.*</AspNetCoreVersion>
12+
<ExtensionsVersion>5.0.*</ExtensionsVersion>
13+
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
814
</PropertyGroup>
915

1016
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netstandard2.0'">
@@ -20,8 +26,8 @@
2026
</PropertyGroup>
2127

2228
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'netcoreapp3.0' Or '$(TargetFramework)' == 'netstandard2.1'">
23-
<AspNetCoreVersion>3.1.3</AspNetCoreVersion>
24-
<ExtensionsVersion>3.1.3</ExtensionsVersion>
29+
<AspNetCoreVersion>3.1.10</AspNetCoreVersion>
30+
<ExtensionsVersion>3.1.10</ExtensionsVersion>
2531
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
2632
</PropertyGroup>
2733

@@ -56,9 +62,9 @@
5662
<ItemGroup Label="Unit Tests">
5763
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.0.1" />
5864
<PackageReference Update="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
59-
<PackageReference Update="Moq" Version="4.13.1" />
65+
<PackageReference Update="Moq" Version="4.15.2" />
6066
<PackageReference Update="xunit" Version="2.4.1" />
61-
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" />
67+
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
6268
</ItemGroup>
6369

6470
<ItemGroup Label="Bet">
@@ -68,7 +74,7 @@
6874

6975
<ItemGroup Label="SourceLink">
7076
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
71-
<PackageReference Include="Bet.CodeAnalyzers" Version="1.0.7" PrivateAssets="All" />
77+
<PackageReference Include="Bet.CodeAnalyzers" Version="1.0.10" PrivateAssets="All" />
7278
</ItemGroup>
7379

7480
<ItemGroup>

build/settings.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup Label="Basic Settings">
4-
<VersionPrefix>3.0.0-preview1</VersionPrefix>
4+
<VersionPrefix>3.0.1-preview1</VersionPrefix>
55
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
66
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
77
<NoWarn>$(NoWarn);CS1591;NU1605;</NoWarn>

src/CronScheduler.AspNetCore/CronScheduler.AspNetCore.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
3+
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1;net5.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<PropertyGroup>

src/CronScheduler.Extensions/CronScheduler.Extensions.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
3+
<TargetFrameworks>netstandard2.0;netstandard2.1;</TargetFrameworks>
44
</PropertyGroup>
55

66
<PropertyGroup>
77
<Description>
8-
The Cron based Scheduler for DotNetCore 2.x/3.0 Self-hosted Applications in Kubernetes/Docker or as WindowsService on Windows Machine.
8+
The Cron based Scheduler for DotNetCore 2.x/3.x Self-hosted Applications in Kubernetes/Docker or as WindowsService on Windows Machine.
99
This is a lightweight alternative to Quarts Scheduler or HangFire.
1010
</Description>
1111
</PropertyGroup>

src/CronScheduler.Extensions/DependencyInjection/SchedulerBuilder.cs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class SchedulerBuilder
2828
public SchedulerBuilder(IServiceCollection services)
2929
{
3030
Services = services ?? throw new ArgumentNullException(nameof(services));
31-
Services.TryAddSingleton<ISchedulerRegistration, SchedulerRegistration>();
3231
}
3332

3433
/// <summary>

src/CronScheduler.Extensions/DependencyInjection/SchedulerServiceCollectionExtensions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ private static void CreateInstance(
9191
IServiceCollection services,
9292
EventHandler<UnobservedTaskExceptionEventArgs>? unobservedTaskExceptionHandler = default)
9393
{
94+
services.TryAddSingleton<ISchedulerRegistration, SchedulerRegistration>();
95+
9496
// should prevent from double registrations.
9597
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, SchedulerHostedService>(sp =>
9698
{

src/CronScheduler.Extensions/Internal/SchedulerRegistration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public SchedulerRegistration(
4545

4646
public bool AddOrUpdate(IScheduledJob job, SchedulerOptions options)
4747
{
48-
return AddOrUpdate(job.GetType().Name, job, options);
48+
return AddOrUpdate(job.Name, job, options);
4949
}
5050

5151
public bool AddOrUpdate(string jobName, IScheduledJob job, SchedulerOptions options)
@@ -55,7 +55,7 @@ public bool AddOrUpdate(string jobName, IScheduledJob job, SchedulerOptions opti
5555

5656
public bool AddOrUpdate(IScheduledJob job)
5757
{
58-
return AddOrUpdate(job.GetType().Name, job);
58+
return AddOrUpdate(job.Name, job);
5959
}
6060

6161
public bool AddOrUpdate(string jobName, IScheduledJob job)

src/CronSchedulerApp/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
# Build image
3-
FROM kdcllc/dotnet:3.0-sdk-buster as builder
3+
FROM kdcllc/dotnet-sdk:3.1-buster as builder
44
WORKDIR ./src/CronSchedulerApp
55
RUN dotnet publish --no-build -c Release -o /app
66

77
# App image
8-
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-preview8-buster-slim AS final
8+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS final
99
WORKDIR /app
1010
COPY --from=builder /app .
1111
ENTRYPOINT ["dotnet", "CronSchedulerApp.dll"]

src/CronSchedulerApp/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class Program
1717
public static async Task Main(string[] args)
1818
{
1919
// run async jobs before the IWebHost run
20-
// AspNetCore 2.x syntaxn of the registration.
20+
// AspNetCore 2.x syntax of the registration.
2121
// var host = CreateWebHostBuilder(args).Build();
2222
var host = CreateHostBuilder(args).Build();
2323

@@ -48,7 +48,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
4848
}
4949

5050
/// <summary>
51-
/// AspNetCore 2.x syntaxn of the registration.
51+
/// AspNetCore 2.x syntax of the registration.
5252
/// </summary>
5353
/// <param name="args"></param>
5454
/// <returns></returns>

src/CronSchedulerApp/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CronSchedulerApp
2+
3+
4+
## Installing Redis Server
5+
6+
- [Installing on Windows with Chocolatey](https://chocolatey.org/packages/redis-64/)
7+
- [Installing on WS2L]()

src/CronSchedulerApp/app.db

0 Bytes
Binary file not shown.

test/CronScheduler.UnitTest/CronScheduler.UnitTest.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<NoWarn>$(NoWarn);SA1402;</NoWarn>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="Bet.Extensions.Testing" />
1111
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
1213
<PackageReference Include="Moq" />
1314
<PackageReference Include="xunit" />
1415
<PackageReference Include="xunit.runner.visualstudio">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
using CronScheduler.Extensions.Scheduler;
5+
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace CronScheduler.UnitTest
9+
{
10+
public class CustomTestJob : IScheduledJob
11+
{
12+
private readonly CustomTestJobOptions _options;
13+
private readonly ILogger<CustomTestJob> _logger;
14+
15+
public CustomTestJob(CustomTestJobOptions options, ILogger<CustomTestJob> logger)
16+
{
17+
_options = options;
18+
_logger = logger;
19+
Name = options.JobName;
20+
}
21+
22+
public string Name { get; }
23+
24+
public Task ExecuteAsync(CancellationToken cancellationToken)
25+
{
26+
_logger.LogInformation("Running {name}", nameof(CustomTestJob));
27+
_logger.LogInformation(_options.DisplayText);
28+
29+
return Task.CompletedTask;
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using CronScheduler.Extensions.Scheduler;
2+
3+
namespace CronScheduler.UnitTest
4+
{
5+
public class CustomTestJobOptions : SchedulerOptions
6+
{
7+
public string DisplayText { get; set; } = string.Empty;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
using Bet.Extensions.Testing.Logging;
6+
7+
using CronScheduler.Extensions.Internal;
8+
using CronScheduler.Extensions.Scheduler;
9+
10+
using Microsoft.Extensions.Configuration;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Microsoft.Extensions.Hosting;
13+
using Microsoft.Extensions.Logging;
14+
15+
using Xunit;
16+
using Xunit.Abstractions;
17+
18+
namespace CronScheduler.UnitTest
19+
{
20+
public class SchedulerRegistrationTests
21+
{
22+
private ITestOutputHelper _output;
23+
24+
public SchedulerRegistrationTests(ITestOutputHelper output)
25+
{
26+
_output = output ?? throw new ArgumentNullException(nameof(output));
27+
}
28+
29+
[Fact]
30+
public async Task Successfully_Register_Two_Jobs_With_The_Same_Type()
31+
{
32+
var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
33+
34+
var services = new ServiceCollection();
35+
36+
services.AddSingleton<IConfiguration>(configuration);
37+
38+
services.AddLogging(builder =>
39+
{
40+
builder.AddDebug();
41+
builder.AddXunit(_output, LogLevel.Debug);
42+
});
43+
44+
services.AddScheduler();
45+
services.AddHostedService<SchedulerHostedService>();
46+
47+
var sp = services.BuildServiceProvider();
48+
var schedulerRegistration = sp.GetRequiredService<ISchedulerRegistration>();
49+
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
50+
51+
var options1 = new CustomTestJobOptions
52+
{
53+
JobName = "Job1",
54+
CronSchedule = "0/2 * * * * *",
55+
RunImmediately = false,
56+
DisplayText = "Every 2 seconds."
57+
};
58+
59+
var options2 = new CustomTestJobOptions
60+
{
61+
JobName = "Job2",
62+
CronSchedule = "0/4 * * * * *",
63+
RunImmediately = false,
64+
DisplayText = "Every 4 seconds."
65+
};
66+
67+
schedulerRegistration.AddOrUpdate(new CustomTestJob(options1, loggerFactory.CreateLogger<CustomTestJob>()), options1);
68+
schedulerRegistration.AddOrUpdate(new CustomTestJob(options2, loggerFactory.CreateLogger<CustomTestJob>()), options2);
69+
70+
var backgroundService = sp.GetService<IHostedService>() as SchedulerHostedService;
71+
await backgroundService.StartAsync(CancellationToken.None);
72+
73+
await Task.Delay(TimeSpan.FromSeconds(15));
74+
75+
await backgroundService.StopAsync(CancellationToken.None);
76+
}
77+
}
78+
}

test/CronScheduler.UnitTest/SchedulerServiceTests.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,30 @@ public void Add_Job_Successfully()
3838

3939
var configuration = new ConfigurationBuilder().AddInMemoryCollection(dic).Build();
4040

41-
var service = new ServiceCollection();
41+
var services = new ServiceCollection();
4242

43-
service.AddSingleton<IConfiguration>(configuration);
43+
services.AddSingleton<IConfiguration>(configuration);
4444

45-
service.AddOptions();
45+
services.AddOptions();
4646

4747
var name = typeof(TestJob).Name;
4848

49-
service.AddOptions<SchedulerOptions>(name)
49+
services.AddOptions<SchedulerOptions>(name)
5050
.Configure<IConfiguration>((options, configuration) =>
5151
{
5252
configuration.Bind("SchedulerJobs:TestJobException", options);
5353
});
5454

55-
service.AddLogging(builder =>
55+
services.AddLogging(builder =>
5656
{
5757
builder.AddConsole();
5858
builder.AddDebug();
5959
builder.AddXunit(_output, LogLevel.Debug);
6060
});
6161

62-
service.AddSingleton<SchedulerRegistration>();
62+
services.AddSingleton<SchedulerRegistration>();
6363

64-
var sp = service.BuildServiceProvider();
64+
var sp = services.BuildServiceProvider();
6565

6666
var instance = sp.GetService<SchedulerRegistration>();
6767

0 commit comments

Comments
 (0)