Git Product home page Git Product logo

crontab's Introduction

Yisoft.Crontab

Build status NuGet

cron expression parser and executor for dotnet core.

this project based on 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:

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<MethodInfo, object> 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 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

License

Released under the Apache License.

crontab's People

Contributors

yiteam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crontab's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.