https://github.com/yisoft-dotnet/crontab
cron expression parser and executor for dotnet core.
https://github.com/yisoft-dotnet/crontab
cron cron-expression crontab crontab-task dotnet dotnet-standard executor scheduled-jobs task-scheduler yisoft yiteam
Last synced: 21 days ago
JSON representation
cron expression parser and executor for dotnet core.
- Host: GitHub
- URL: https://github.com/yisoft-dotnet/crontab
- Owner: yisoft-dotnet
- License: apache-2.0
- Created: 2017-04-13T13:52:25.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-27T07:51:32.000Z (over 8 years ago)
- Last Synced: 2025-08-01T01:03:35.563Z (6 months ago)
- Topics: cron, cron-expression, crontab, crontab-task, dotnet, dotnet-standard, executor, scheduled-jobs, task-scheduler, yisoft, yiteam
- Language: C#
- Homepage: https://yi.team
- Size: 47.9 KB
- Stars: 14
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yisoft.Crontab #
[](https://ci.appveyor.com/project/yiteam/crontab)
[](https://www.nuget.org/packages/Yisoft.Crontab/)
cron expression parser and executor for dotnet core.
> this project based on [NCrontab-Advanced](https://github.com/jcoutch/NCrontab-Advanced).
If you have any problems, make sure to file an issue here on Github.
# Crontab task executor #
## CronAttribute ##
This library support annotation method only. if you want create a crontab task, simply add the `CronAttribute` on some method.
We also provide some advanced features that you can get by adding some parameters to the method to get the information associated with the current task.
Here are some [samples](sample):
```csharp
public class TestScheduler
{
[Cron("18/1 * * * * ? *", CronStringFormat.WithSecondsAndYears)]
public static void Task1()
{
Debug.WriteLine($"Task..............1111_{DateTime.Now}");
}
[Cron("28/1 * * * * ? *", CronStringFormat.WithSecondsAndYears)]
public static void Task2(DateTime time, CrontabTask task)
{
Debug.WriteLine($"Task..............2222_{time}_{task.Method.Name}");
}
[Cron("28/1 * * * * ? *", CronStringFormat.WithSecondsAndYears)]
public static void Task3(DateTime time, CrontabTask task)
{
Debug.WriteLine($"Task..............3333_{time}_{task.Method.Name}");
}
[Cron("1-8 * * * * ? *", CronStringFormat.WithSecondsAndYears)]
[Cron("48/1 * * * * ? *", CronStringFormat.WithSecondsAndYears)]
public static void Task4(DateTime time, CrontabTask task, CrontabTaskExecutor taskExecutor)
{
Debug.WriteLine($"Task..............Cron_{time}_{task.Method.Name}_{taskExecutor.Tasks.Count}");
}
// this task will begin execution after 100 seconds of startup
[Cron("0/1 * * * * *", 100, CronStringFormat.WithSeconds)]
public static void DeferTask1()
{
Debug.WriteLine($"Task..............5555_{DateTime.Now}");
}
}
```
## Constructor ##
The `CrontabTaskExecutor` class contains a constructor that with one parameter, the parameter is `Func typeInstanceCreator`. `typeInstanceCreator` used to create an object instance where the task method is definded. this will be very useful!
In console application, you can initialize an instance of an object with the `new` keyword or reflection. and in web application, you can use `DI`(`dependency injection`) directly.
For better use this library in your Web application, see the [Yisoft.AspNetCore.Crontab](https://github.com/yisoft-aspnet/crontab) project.
# Support for the following cron expressions #
```
Field name | Allowed values | Allowed special characters
------------------------------------------------------------
Minutes | 0-59 | * , - /
Hours | 0-23 | * , - /
Day of month | 1-31 | * , - / ? L W
Month | 1-12 or JAN-DEC | * , - /
Day of week | 0-6 or SUN-SAT | * , - / ? L #
Year | 0001–9999 | * , - /
```
## Related community projects
* [Yisoft.AspNetCore.Crontab](https://github.com/yisoft-aspnet/crontab)
# License
Released under the [Apache License](License.txt).