Chd.Library.Services
9.0.4
See the version list below for details.
dotnet add package Chd.Library.Services --version 9.0.4
NuGet\Install-Package Chd.Library.Services -Version 9.0.4
<PackageReference Include="Chd.Library.Services" Version="9.0.4" />
paket add Chd.Library.Services --version 9.0.4
#r "nuget: Chd.Library.Services, 9.0.4"
// Install Chd.Library.Services as a Cake Addin #addin nuget:?package=Chd.Library.Services&version=9.0.4 // Install Chd.Library.Services as a Cake Tool #tool nuget:?package=Chd.Library.Services&version=9.0.4
Service library for .Net Core
Chd (cleverly handle difficulty) library helps you cleverly handle difficulty, writing code fastly and do your application stable.
π Table of Contents
π§ About
I'm computer engineer for 14 years. I wrote this package for implement service simlfy. This services contains cron syntax.
π Getting Started
Before setting up cron jobs, you must understand cronβs syntax and formatting to ensure the script runs properly. The crontab syntax consists of five fields with the following possible values:
Minute. The minute of the hour the command will run, ranging from 0-59.
Hour. The hour the command will run, ranging from 0-23 in a 24-hour notation.
Day of the month. The date of the month the user wants the command to run, ranging from 1-31.
Month. The month that the user wants the command to run. It ranges from 1-12, representing January until December.
Day of the week. The day of the week for a command to run, ranging from 0-6. The value represents Sunday-Saturday. In some systems, the value 7 represents Sunday.
In addition to the syntax, you must understand the cron job operators to modify the value in each field. You must properly use these operators in all crontab files to ensure your commands run:
Asterisk (*). This operator signifies all possible values in a field. For example, write an asterisk in the Minute field to make the cron job run every minute.
Comma (,). An operator for listing multiple values. For example, writing 1,5 in the day-of-week field will schedule the job to run every Monday and Friday.
Hyphen (-). Users can determine a range of values. Write 6-9 in the Month field to set up a cron job from June to September.
Separator (/). This separator divides a value. If you want to run a script every twelve hours, write */12 in the Hour field.
Last (L). Users can use this operator in the day-of-month and day-of-week fields. For example, writing 3L in the day-of-week field means the last Wednesday of the month.
Weekday (W). An operator that determines the closest weekday from a given time. For example, if the 1st of a month is a Saturday, writing 1W in the day-of-month field will run the command on Monday the 3rd.
Hash (#). An operator for the day-of-week field that determines a specific day of the month, using a number between 1 to 5. For instance, 1#2 means the second Monday of the month.
Question mark (?). This operator inputs no specific value for the day-of-month and day-of-week fields. Itβs typically replaced with the cron daemon start-up time.
A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows:
* * * * * *
- - - - - -
| | | | | |
| | | | | + year [optional]
| | | | +----- day of week (0 - 7) (Sunday=0 or 7)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
π Usage
π§ Create Cron Job Service Class
We need a class created by inheriting from the "CronJobService" class.
[CronJob("*/1 * * * *")] //once a minute
public class SampleCronJobService : CronJobService
{
public override void Run(CancellationToken cancellationToken)
{
//Write code here
}
}
π Injection Service To Application
We need to inject the class we created above into the application. In this way, our service is ready.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCronJobService<SampleCronJobService>();
After running the application, the service's "Run" method work once a minute.
βοΈ Authors
- @yoldasmehmet - Idea & Initial work
See also the list of contributors who participated in this project.
π Acknowledgements
Thank you for using my library.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Chd.Library.Common (>= 9.0.8)
- Cronos (>= 0.7.1)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.