-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
These files contain various utility functions, classes, and configuration settings which are essential for the operation of cron jobs in the application. This includes classes for handling cron expressions, options for cron jobs, and extension methods for int32 and DateTime, among others. It also adds configuration files for the project.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Merge Workflow | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
merge_job: | ||
name: Merge Job | ||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | ||
uses: frankhaugen/Workflows/.github/workflows/dotnet-publish-preview.yml@main | ||
secrets: inherit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Pull Request Workflow | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
pull_request_job: | ||
name: Pull Request Job | ||
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' | ||
uses: frankhaugen/Workflows/.github/workflows/dotnet-pull-request.yml@main | ||
secrets: inherit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Release Workflow | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release_job: | ||
name: Release Job | ||
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' | ||
uses: frankhaugen/Workflows/.github/workflows/dotnet-publish-release.yml@main | ||
secrets: inherit | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>true</IsPackable> | ||
|
||
<Description>Frank.CronJobs is a library for running cron jobs in .NET Core applications.</Description> | ||
<PackageTags>dotnet, cron, job, jobs, cronjob, cronjobs, run, running, async, di, dependency, injection, host, hosting, schedule, scheduled, Frank Haugen, Frank, Haugen, Frank R. Haugen</PackageTags> | ||
|
||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<NoWarn>$(NoWarn);1591</NoWarn> | ||
|
||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>portable</DebugType> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
|
||
<Authors>Frank R. Haugen</Authors> | ||
<PublisherName>Frank R. Haugen</PublisherName> | ||
<Copyright>Copyright (c) 2023 Frank R. Haugen</Copyright> | ||
|
||
<PackageReadmeFile>readme.md</PackageReadmeFile> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://www.github.com/frankhaugen/Frank.CronJobs</PackageProjectUrl> | ||
|
||
<RepositoryUrl>https://www.github.com/frankhaugen/Frank.CronJobs</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/> | ||
<None Include="../readme.md" Pack="true" PackagePath="\"/> | ||
<None Include="../icon.png" Pack="true" PackagePath="\"/> | ||
<InternalsVisibleTo Include="$(AssemblyName).Tests"/> | ||
<InternalsVisibleTo Include="LINQPadQuery"/> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Frank.CronJobs.DependencyInjection; | ||
using Frank.CronJobs.Jobs; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit.Abstractions; | ||
|
||
namespace Frank.CronJobs.Tests.DependencyInjection; | ||
|
||
public class ServiceCollectionExtensionsTests | ||
{ | ||
private readonly ITestOutputHelper _outputHelper; | ||
public ServiceCollectionExtensionsTests(ITestOutputHelper outputHelper) | ||
{ | ||
_outputHelper = outputHelper; | ||
} | ||
|
||
[Fact] | ||
public async Task AddCronJob_WithCronExpression_ShouldRunAsync() | ||
{ | ||
// Arrange | ||
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
var host = Host.CreateDefaultBuilder() | ||
.ConfigureAppConfiguration((context, builder) => | ||
{ | ||
builder.AddInMemoryCollection(new Dictionary<string, string> | ||
Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs GitHub Actions / Release Job / Release Job
Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs GitHub Actions / Release Job / Release Job
Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs GitHub Actions / Release Job / Release Job
Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs GitHub Actions / Release Job / Release Job
|
||
{ | ||
{"CronJobRunnerOptions:Running", "true"}, | ||
}); | ||
}) | ||
.ConfigureServices((context, services) => | ||
{ | ||
services.AddLogging(builder => builder.AddXunit(_outputHelper)); | ||
services.AddCronJobs(context.Configuration, cronJobBuilder => | ||
{ | ||
cronJobBuilder.AddCronJob<MyService>(options => | ||
{ | ||
options.Cron = "* * * * * *"; | ||
options.Running = true; | ||
}); | ||
cronJobBuilder.AddCronJob<MyOtherService>(options => | ||
{ | ||
options.Cron = "* * * * * *"; | ||
options.Running = true; | ||
}); | ||
}); | ||
}) | ||
.Build(); | ||
|
||
// Act | ||
await host.RunAsync(cancellationTokenSource.Token); | ||
|
||
// Assert | ||
_outputHelper.WriteLine("Finished"); | ||
} | ||
|
||
private class MyService : ICronJob | ||
{ | ||
private readonly ILogger<MyService> _logger; | ||
|
||
public MyService(ILogger<MyService> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async Task RunAsync() | ||
{ | ||
_logger.LogInformation("Running"); | ||
await Task.Delay(100); | ||
} | ||
} | ||
|
||
private class MyOtherService : ICronJob | ||
{ | ||
private readonly ILogger<MyOtherService> _logger; | ||
|
||
public MyOtherService(ILogger<MyOtherService> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async Task RunAsync() | ||
{ | ||
_logger.LogInformation("Running other"); | ||
await Task.Delay(100); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Divergic.Logging.Xunit" Version="4.3.0" /> | ||
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Frank.CronJobs\Frank.CronJobs.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frank.CronJobs", "Frank.CronJobs\Frank.CronJobs.csproj", "{316667F8-7EC7-42E1-AEC7-035FFBC73C25}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D8F3A60B-01A8-45ED-9299-5FA58CB953A1}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
Directory.Build.props = Directory.Build.props | ||
LICENSE = LICENSE | ||
nuget.config = nuget.config | ||
README.md = README.md | ||
icon.png = icon.png | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frank.CronJobs.Tests", "Frank.CronJobs.Tests\Frank.CronJobs.Tests.csproj", "{95666C2E-71F1-4F75-AB9E-7EB1BEBD74A9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{316667F8-7EC7-42E1-AEC7-035FFBC73C25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{316667F8-7EC7-42E1-AEC7-035FFBC73C25}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{316667F8-7EC7-42E1-AEC7-035FFBC73C25}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{316667F8-7EC7-42E1-AEC7-035FFBC73C25}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{95666C2E-71F1-4F75-AB9E-7EB1BEBD74A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{95666C2E-71F1-4F75-AB9E-7EB1BEBD74A9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{95666C2E-71F1-4F75-AB9E-7EB1BEBD74A9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{95666C2E-71F1-4F75-AB9E-7EB1BEBD74A9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |