Skip to content

Commit

Permalink
Add various new files for cron job functionalities
Browse files Browse the repository at this point in the history
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
frankhaugen committed Dec 30, 2023
1 parent db46e21 commit 6438dba
Show file tree
Hide file tree
Showing 34 changed files with 1,544 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/merge.yml
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
13 changes: 13 additions & 0 deletions .github/workflows/pull-request.yml
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
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
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

13 changes: 13 additions & 0 deletions .idea/.idea.Frank.CronJobs/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.Frank.CronJobs/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Frank.CronJobs/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Frank.CronJobs/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Directory.Build.props
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

View workflow job for this annotation

GitHub Actions / Release Job / Release Job

Argument of type 'Dictionary<string, string>' cannot be used for parameter 'initialData' of type 'IEnumerable<KeyValuePair<string, string?>>' in 'IConfigurationBuilder MemoryConfigurationBuilderExtensions.AddInMemoryCollection(IConfigurationBuilder configurationBuilder, IEnumerable<KeyValuePair<string, string?>>? initialData)' due to differences in the nullability of reference types.

Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Release Job / Release Job

Argument of type 'Dictionary<string, string>' cannot be used for parameter 'initialData' of type 'IEnumerable<KeyValuePair<string, string?>>' in 'IConfigurationBuilder MemoryConfigurationBuilderExtensions.AddInMemoryCollection(IConfigurationBuilder configurationBuilder, IEnumerable<KeyValuePair<string, string?>>? initialData)' due to differences in the nullability of reference types.

Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Release Job / Release Job

Argument of type 'Dictionary<string, string>' cannot be used for parameter 'initialData' of type 'IEnumerable<KeyValuePair<string, string?>>' in 'IConfigurationBuilder MemoryConfigurationBuilderExtensions.AddInMemoryCollection(IConfigurationBuilder configurationBuilder, IEnumerable<KeyValuePair<string, string?>>? initialData)' due to differences in the nullability of reference types.

Check warning on line 27 in Frank.CronJobs.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Release Job / Release Job

Argument of type 'Dictionary<string, string>' cannot be used for parameter 'initialData' of type 'IEnumerable<KeyValuePair<string, string?>>' in 'IConfigurationBuilder MemoryConfigurationBuilderExtensions.AddInMemoryCollection(IConfigurationBuilder configurationBuilder, IEnumerable<KeyValuePair<string, string?>>? initialData)' due to differences in the nullability of reference types.
{
{"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);
}
}
}
30 changes: 30 additions & 0 deletions Frank.CronJobs.Tests/Frank.CronJobs.Tests.csproj
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>
1 change: 1 addition & 0 deletions Frank.CronJobs.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
38 changes: 38 additions & 0 deletions Frank.CronJobs.sln
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
Loading

0 comments on commit 6438dba

Please sign in to comment.