Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRON expressions #34

Closed
hoghweed opened this issue Nov 25, 2013 · 9 comments
Closed

CRON expressions #34

hoghweed opened this issue Nov 25, 2013 · 9 comments

Comments

@hoghweed
Copy link

Hi,
I've chosen your implementation of a task scheduler because I like the codebase and the fact that the code is using the TPL.

I need to extend the library to support the ability to schedule based on cron espressions. I saw that the Schedule CalculateNextRun Func is internal, so It's impossible for me to implement such a thing.

Now I have to import all your codebase in my project, modified for my needs, but this is not what I really want, so it's possible to have a version which enables extensions?

Thanks

@vkaldi
Copy link
Contributor

vkaldi commented Nov 25, 2013

Hmm, maybe the better way would be to extend the fluent scheduler codebase with a "cron expression parser".
For instance, it would be great if we would write something like this:

FluentScheduler.TaskManager.AddTask(() => { }, x => x.FromExpression("0 * 14 * * ?"));

So in essence, you could create Scheduler.FromExpression() which would parse cron expression and return (or fill the properties of the existing class) Scheduler.

@hoghweed
Copy link
Author

Ok, I'm working on an implementation, but It still needs to be done in the codebase, this because the properties to fill of the Schedule are internal! The class should be the Schedule, no Scheduler class is there...

@jbrantly
Copy link

I second opening up the CalculateNextRun property. It seems like a great extension point to be able to do all sorts of fancy scheduling stuff. I recently achieved the use of cron expressions by using the NCrontab project (https://code.google.com/p/ncrontab/) whose "GetNextOccurrence" function works perfectly with CalculateNextRun. I just bypassed the internal flag by using reflection.

var crontabSchedule = NCrontab.CrontabSchedule.Parse(schedule, new CrontabSchedule.ParseOptions() {IncludingSeconds = true});
s.GetType()
  .GetProperty("CalculateNextRun", BindingFlags.NonPublic | BindingFlags.Instance)
  .SetValue(s, (Func<DateTime, DateTime>) crontabSchedule.GetNextOccurrence, null);

I think this is a great example though of how opening up this property can enable some advanced scenarios.

@tallesl tallesl added the on hold label Mar 2, 2016
@tallesl tallesl changed the title Ability to extend the Schedule class or to support custom scheduling calculation Support custom scheduling calculation Mar 2, 2016
@tallesl
Copy link
Contributor

tallesl commented Mar 2, 2016

I'm putting this on "on hold" (for comments and opinions from others), even though is an old issue.

I don't know if I like the idea of the consumer hooking up how the calculation is done but supporting cron out of the box might not be a bad idea...

@Thanood
Copy link
Contributor

Thanood commented Mar 2, 2016

As far as I can see Schedule.cs (a public class) is using the builder pattern. So IMO you could support "builder-style" extension methods in that class, right?

These methods - for example FromCronExpression(expression) - could parse the expression and use the builder Methods which are already provided.

So "0 0/5 * 1/1 * ? *" would call .ToRunEvery(5).Minutes() (if I recall that correctly).

But I'm not sure if that's practical at all because I'm not that experienced with cron calculation. 😄

@tallesl tallesl removed the on hold label Aug 8, 2016
@tallesl tallesl changed the title Support custom scheduling calculation CRON expressions Aug 8, 2016
@nvsoares
Copy link

nvsoares commented Jan 2, 2017

Hi @tallesl.
When do you think to provide support for scheduling from cron expressions?
Is very useful and important to give the applications the flexibility that each client / work needs.

@jozefizso
Copy link

With internal Schedule.CalculateNextRun we cannot implement our custom ITimeRestrictableUnit types.

It will help to make this property public.

@MERamadan
Copy link

Any updates on this feature? It is idle for 4 years now.
Cron expressions are a curcial feature for any scheduling engine to be able to have flexibility on job schedules and store/load the jobs schedules from a database.

@tallesl
Copy link
Contributor

tallesl commented Sep 2, 2018

See #214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants