Skip to content

Commit

Permalink
Merge pull request #50 from kdcllc/dev
Browse files Browse the repository at this point in the history
Deps and IServiceCollection for UnobservedTaskExceptionHandler
  • Loading branch information
kdcllc authored Jun 12, 2022
2 parents 2e11249 + ab3a67c commit 211e274
Show file tree
Hide file tree
Showing 70 changed files with 1,980 additions and 2,057 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ BenchmarkDotNet.Artifacts/
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

# StyleCop
StyleCopReport.xml
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@
Change Log
===============================================================================

Version 3.1.0 (6/12/2022)

* `SchedulerBuilder.UnobservedTaskExceptionHandler` marked as `Obsolete`;

* Adds a function to create an event handler that handles unobserved task exceptions during the lifetime of the CRON job. Thanks to @stijnmoreels

```csharp
builder.AddUnobservedTaskExceptionHandler(sp =>
{
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("CronJobs");

return
(sender, args) =>
{
logger?.LogError(args.Exception?.Message);
args.SetObserved();
};
});
```

Version 3.0.1

* Fixed issue with Scheduled jobs that are added on the fly to the execution engine issue #43
* Upgraded to the latest nuget packages

Expand Down Expand Up @@ -30,6 +51,7 @@ Version 1.0.9 (2019-02-18)
* Removed `HostedServiceBase` class in favor of built-in `BackgroundService` class.

Version 1.0.7 (2018-01-16)

* Resolved issue #5 "Add support for SourceLink", to make use of this feature in Visual Studio.NET please deselect `Enable Just My Code` and select `Enable Source Link support` as shown per this image:
![enable](img/source_link_enable.JPG)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 King David Consulting LLC
Copyright (c) 2017-2022 King David Consulting LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

The goal of this library was to design a simple Cron Scheduling engine that could be used with DotNetCore `IHost` or with AspNetCore `IWebHost`.

It is much lighter than Quartz schedular or its alternatives. In the heart of its design was `KISS` principle.
It is much lighter than Quartz schedular or its alternatives. The `KISS` principle was at the heart of the development of this library.

The `CronScheduler` can operate inside of any .NET Core GenericHost `IHost` thus makes it simpler to setup and configure but it always allow to be run inside of Kubernetes.

Expand Down Expand Up @@ -162,8 +162,19 @@ The sample uses `Microsoft.Extensions.Http.Polly` extension library to make http
builder.Services.AddHttpClient<TorahService>()
.AddTransientHttpErrorPolicy(p => p.RetryAsync());
builder.AddJob<TorahQuoteJob, TorahQuoteJobOptions>();

// register a custom error processing for internal errors
builder.AddUnobservedTaskExceptionHandler(sp =>
{
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("CronJobs");

builder.UnobservedTaskExceptionHandler = UnobservedHandler;
return
(sender, args) =>
{
logger?.LogError(args.Exception?.Message);
args.SetObserved();
};
});
});
```

Expand Down Expand Up @@ -209,7 +220,18 @@ Then register this service within the `Startup.cs`
builder.Services.AddScoped<UserService>();
builder.AddJob<UserJob, UserJobOptions>();

builder.UnobservedTaskExceptionHandler = UnobservedHandler;
// register a custom error processing for internal errors
builder.AddUnobservedTaskExceptionHandler(sp =>
{
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("CronJobs");

return
(sender, args) =>
{
logger?.LogError(args.Exception?.Message);
args.SetObserved();
};
});
});
```

Expand Down Expand Up @@ -284,22 +306,6 @@ Then add sample async task to be executed by the Queued Hosted Service.
}
```

## Docker build

Utilizes [King David Consulting LLC DotNet Docker Image](https://github.com/kdcllc/docker/tree/master/dotnet)

```bash
docker-compose -f "docker-compose.yml" -f "docker-compose.override.yml" up -d --build
```

### Note

Workaround for `Retrying 'FindPackagesByIdAsync' for source` in Docker containers restore.

```bash
dotnet restore --disable-parallel
```

## License

[MIT License Copyright (c) 2017 King David Consulting LLC](./LICENSE)
[MIT License Copyright (c) 2017-2022 King David Consulting LLC](./LICENSE)
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: 3.0.{build}
version: 3.1.{build}
branches:
only:
- master
pull_requests:
do_not_increment_build_number: true
image: Visual Studio 2017
## temporary until 5.0.100 sdk is installed
image: Visual Studio 2022
## temporary until 6.0.300 sdk is installed
install:
- ps: $urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/5.0.100/dotnet-sdk-5.0.100-win-x64.zip"
- ps: $urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/6.0.300/dotnet-sdk-6.0.300-win-x64.zip"
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
- ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
- ps: $tempFileCurrent = [System.IO.Path]::GetTempFileName()
Expand All @@ -33,6 +33,6 @@ deploy:
- provider: NuGet
artifact: /NuGet/
api_key:
secure: hs4f+3xdpI1ANqvOB7J9BZx+aBdbZYzHmoYymDFA7YCt5AWLJSdNyv2nkrBn1V9q
secure: a8sCawSwgb2kYDJAN+xTUvy+MH5jdJR+DmKakUmc/Xom1c+uxyvV+yvpSTJs+ypF
on:
branch: master
123 changes: 53 additions & 70 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,84 +1,67 @@
<Project>

<PropertyGroup>
<AspNetCoreVersion>2.1.1</AspNetCoreVersion>
<ExtensionsVersion>2.1.1</ExtensionsVersion>
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
<BetCommon>3.1.11</BetCommon>
</PropertyGroup>
<PropertyGroup>
<AspNetCoreVersion>[6.*, )</AspNetCoreVersion>
<ExtensionsVersion>[6.*, )</ExtensionsVersion>
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
<BetCommon>[4.*, )</BetCommon>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'net5.0'">
<AspNetCoreVersion>5.0.*</AspNetCoreVersion>
<ExtensionsVersion>5.0.*</ExtensionsVersion>
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
</PropertyGroup>
<ItemGroup Label="CronScheduler">
<PackageReference Update="Cronos" Version="0.7.1" />
<PackageReference Update="Microsoft.AspNetCore.Hosting" Version="$(AspNetCoreVersion)" />
<PackageReference Update="Microsoft.Extensions.Hosting.Abstractions" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="[1.*, )" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netstandard2.0'">
<AspNetCoreVersion>2.1.1</AspNetCoreVersion>
<ExtensionsVersion>2.1.1</ExtensionsVersion>
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
</PropertyGroup>
<ItemGroup Label="Websiste">
<PackageReference Update="Microsoft.Extensions.Http.Polly" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="$(AspNetCoreVersion)"/>
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.2'">
<AspNetCoreVersion>[2.2.*, )</AspNetCoreVersion>
<EFCommonVersion>[2.2.*, )</EFCommonVersion>
<ExtensionsVersion>[2.2.*, )</ExtensionsVersion>
</PropertyGroup>
<ItemGroup Label="EF">
<PackageReference Update="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Identity.UI" Version="$(EFCommonVersion)" />

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'netcoreapp3.0' Or '$(TargetFramework)' == 'netstandard2.1'">
<AspNetCoreVersion>3.1.10</AspNetCoreVersion>
<ExtensionsVersion>3.1.10</ExtensionsVersion>
<EFCommonVersion>$(AspNetCoreVersion)</EFCommonVersion>
</PropertyGroup>
<PackageReference Update="Microsoft.EntityFrameworkCore.Relational" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Tools" Version="$(EFCommonVersion)"/>
</ItemGroup>

<ItemGroup Label="CronScheduler">
<PackageReference Update="Cronos" Version="0.7.0" />
<PackageReference Update="Microsoft.AspNetCore.Hosting" Version="$(AspNetCoreVersion)" />
<PackageReference Update="Microsoft.Extensions.Hosting.Abstractions" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="$(ExtensionsVersion)" />
</ItemGroup>
<ItemGroup Label="Worker">
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(ExtensionsVersion)" />
</ItemGroup>

<ItemGroup Label="Websiste">
<PackageReference Update="Microsoft.Extensions.Http.Polly" Version="$(ExtensionsVersion)" />
<PackageReference Update="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="$(AspNetCoreVersion)"/>
</ItemGroup>
<ItemGroup Label="Unit Tests">
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Update="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
<PackageReference Update="Moq" Version="4.*" />
<PackageReference Update="xunit" Version="2.*" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.*" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Label="EF">
<PackageReference Update="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.AspNetCore.Identity.UI" Version="$(EFCommonVersion)" />
<ItemGroup Label="Bet">
<PackageReference Update="Bet.Extensions.Options" Version="$(BetCommon)" />
<PackageReference Update="Bet.Extensions.Testing" Version="$(BetCommon)" />
</ItemGroup>

<PackageReference Update="Microsoft.EntityFrameworkCore.Relational" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFCommonVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Tools" Version="$(EFCommonVersion)"/>
</ItemGroup>
<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.*" PrivateAssets="All" />
<PackageReference Include="Bet.CodeAnalyzers" Version="1.0.12" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Label="Worker">
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(ExtensionsVersion)" />
</ItemGroup>
<ItemGroup>
<None Include="../../img/icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<ItemGroup Label="Unit Tests">
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Update="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
<PackageReference Update="Moq" Version="4.15.2" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Label="Bet">
<PackageReference Update="Bet.Extensions.Options" Version="$(BetCommon)" />
<PackageReference Update="Bet.Extensions.Testing" Version="$(BetCommon)" />
</ItemGroup>

<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Bet.CodeAnalyzers" Version="1.0.10" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Include="../../img/icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
6 changes: 2 additions & 4 deletions build/settings.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<Project>

<PropertyGroup Label="Basic Settings">
<VersionPrefix>3.0.1-preview1</VersionPrefix>
<VersionPrefix>3.1.0-preview1</VersionPrefix>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<NoWarn>$(NoWarn);CS1591;NU1605;</NoWarn>
<TieredCompilation>true</TieredCompilation>
<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -28,7 +26,7 @@
<RepositoryType>git</RepositoryType>
<PackageLicense>https://github.com/kdcllc/CronScheduler.AspNetCore/blob/master/LICENSE</PackageLicense>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>Cron, Quatz, HangFire, AspNetCore, DotNet, DotNetCore CronNET, Scheduler, Worker, Hosting, Kubernetes, Docker</PackageTags>
<PackageTags>CronScheduler.AspNetCore, CronScheduler.Extensions, Cron, Quatz, HangFire, AspNetCore, DotNet, DotNetCore CronNET, Scheduler, Worker, Hosting, Kubernetes, Docker</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

</PropertyGroup>
Expand Down
6 changes: 0 additions & 6 deletions build/sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<RestoreSources>$(DotNetRestoreSources)</RestoreSources>
<RestoreSources Condition="'$(DotNetBuildOffline)' != 'false'">
$(RestoreSources);
https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore/index.json;
https://dotnetfeed.blob.core.windows.net/aspnet-blazor/index.json;
https://dotnetfeed.blob.core.windows.net/aspnet-entityframeworkcore/index.json;
https://dotnetfeed.blob.core.windows.net/aspnet-extensions/index.json;
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
https://www.myget.org/F/kdcllc/api/v3/index.json;
https://api.nuget.org/v3/index.json;
</RestoreSources>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
7 changes: 4 additions & 3 deletions src/CronScheduler.AspNetCore/CronScheduler.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<Description>
The Cron based Scheduler for AspNetCore 2.x/3.x Applications in Kubernetes/Docker.
The Cron based Scheduler for AspNetCore 2.x/3.x/5.x/6.x Applications in Kubernetes/Docker.
This is a lightweight alternative to Quarts Scheduler or HangFire.
</Description>
</PropertyGroup>
Expand All @@ -15,8 +15,9 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Hosting" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.*"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CronScheduler.Extensions\CronScheduler.Extensions.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@

using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Hosting
namespace Microsoft.AspNetCore.Hosting;

public static class StartupJobWebHostExtensions
{
public static class StartupJobWebHostExtensions
/// <summary>
/// Runs async all of the registered <see cref="IStartupJob"/> jobs.
/// </summary>
/// <param name="host"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task RunStartupJobsAync(this IWebHost host, CancellationToken cancellationToken = default)
{
/// <summary>
/// Runs async all of the registered <see cref="IStartupJob"/> jobs.
/// </summary>
/// <param name="host"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task RunStartupJobsAync(this IWebHost host, CancellationToken cancellationToken = default)
{
using (var scope = host.Services.CreateScope())
{
var jobInitializer = scope.ServiceProvider.GetRequiredService<StartupJobInitializer>();
await jobInitializer.StartJobsAsync(cancellationToken);
}
}
using var scope = host.Services.CreateScope();
var jobInitializer = scope.ServiceProvider.GetRequiredService<StartupJobInitializer>();
await jobInitializer.StartJobsAsync(cancellationToken);
}
}
Loading

0 comments on commit 211e274

Please sign in to comment.