So I've decided to use Quartz.NET to schedule some tasks for me in my application and I'd like to schedule my tasks to run daily from the following 3 pieces of information.
TimeSpan startTime //i.e. 10:30
TimeSpan endTime // i.e. 18:30
TimeSpan repeatInterval // 30 Minutes
And the trigger will fire every day at 10:30, 11:00, 11:30...18:30
Seems pretty simple right? But I can't seem to find anything in the TriggerUtils that would allow me to do something like this. I've also tried the CronTrigger route but it doesn't seem very clean for intervals like 90 seconds.
If there's a built in way to do this I'd love to use it but if not I'm ready to roll my own Trigger. Any pointers for implementing a Trigger from scratch (which methods need to be overridden etc.) would also be much appreciated.
You could define a SimpleTrigger with the repeat interval you want and restrict it to run within a daily time range with a DailyCalendar.
Related
I have a schedule that indicates the opening time of a service!
it's a schedule of intervals, so from 8:00 to 1:00 it's ON from 1:00 to 2:00 it's OFF, from 2:00 to 6:00 it's ON again and from 6:00 to 8:00 it's OFF.
Is it possible to change dynamically the opening times, so to vary these intervals through some parameters?
If there are only 2 or 3 alternative schedules then it is worth defining them explicitly as separate objects and using them this way.
Another option: Schedule objects have a concept of Exceptions - this is where it is possible to change the value (in this case ON instead of OFF) of the schedule for a particular period of time. These can be done via interface or programmatically using addException() method. Please see more here.
Furthermore, it is possible to create schedules programmatically. There is actually an example model in AnyLogic that shows how to do it. Please see "Schedule created programmatically" in your "AnyLogic => Help => Example Models => How to models".
Unfortunately, programmatically created schedules lack Action property, however this can be achieved by having an Event object with a conditional trigger which triggers when schedule.getValue() returns true.
I am currently doing a simulation model in AnyLogic of a Distribution Center where from Monday to Saturday I use an event to trigger the loading of a truck. I wish to program this loading every day at the same time, but how can I do it so it happens everyday EXCEPT Sundays. I currently have it as triggered: timeout and mode: cyclic, using calendar dates...
sure, the easy way is to just add a manual exception to the schedule as below:
And the more advanced way is to use a Dynamic Event that executes your daily action.
In the model start code, call create_MyDynamicEvent(7, DAY) to make it trigger after the first 7 days of the sim.
Then in the Dynamic Event action code, add whatever should happen every day. And also add a line that re-creates the same Dynamic event in 1 day, like
create_MyDynamicEvent(1, DAY)
This would then trigger every day, even Sunday. To avoid that, you can add an if-clause in the dynamic event action code to only execute your code if it is not Sunday.
In our app, we have an ability to schedule tasks and we converting this functionality to Quartz. One of the problems that I have is scheduling recurring task that should run, for example, every third day.
The cron expression that I had in mind first of all is:
0 37 18 */3 * ? *
But what this will do, is execute that job on 1,4,7, etc... Which is fine, assuming that I want to start from the first day of the month. However, how to deal with this issue if I need to start from 11th?
I could do something like this:
0 37 18 11/3 * ? *
But, in this case, I will always miss all the days before the 11th.
Also, when the time comes for the next month, the expectation that the day of the month will now be different (on one month the job executed on 1st, and on another it could be on 2/3), but based on the cron above it will restart on the same day (e.g. 1st).
I could, of course, count using hours, but then I will have an issue with day light saving?
What is the correct way to organize it? Or am I missing something?
UPDATE
Possible solution is to use simple trigger, as per http://www.quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/BiDailyTrigger.
But in this case, how do I resolve DST problem?
Thanks,
In continuation of:
What is the most reliable way to schedule a job with cron scheduler is Quartz that repeats every N days starting from a specific date
&
Absolutely unexplainable results for cron based scheduler in Quartz
There is another question regarding possibilities of scheduling with quartz. And the difference between the two above and this one and the fact that I am trying to execute more than a single job for the target period (e.g. Mon, Fri every 4th week)
Let's assume that a user needs to execute a task every 4th week on Wednesday & Friday starting from a specific date.
Of course, I can setup a cron scheduler that will look something like this:
0 0 12 ? 1/4 WED,FRI *
But we are beck to the same problem as described in the linked posts. What this cron expression really mean, is execute the job on Wednesday & Friday of every 4th week of the month.
Another option is to use, calendar interval schedule builder (the perfectly resolves the problem for as long as there is only one day of the week that needs to be considered); however, it does not allow to specify days of a week, but simply calculates the true 4 weeks worth of time based on the start date.
How, if possible, to schedule a job with Quartz, that will be executed every 4th (or any Nth week) on more than a single day of the week? Is it possible to achieve it without multiple triggers?
Thanks,
So, after long digging around, it seems like the only way to solve it with existing Quartz tools is to manage this type of scheduling with more that one trigger (one for every weekday).
Hopefully that helps somebody.
I am using Quart Scheduler. I want to trigger to in such a fashion so as it excludes timing from xx:xx:xx to yy:yy:yy on day specified (monday, friday. sunday). I know how to exclude particular day. but don't know how not to trigger on given time block on given day?
Can anybody know anything about it?
Please make use of Calendar and HolidayCalendar available in Quartz to achieve this. The Cron expression in Cron-Trigger can also be written smartly to achieve this as well.
Looking at http://www.quartz-scheduler.org/docs/examples/Example3.html, it seems that one can create different job set to do the same task. For each job one can attach a schedule.
If you dont want to run a particular task on say sunday between 1pm and 10pm, but want it to run on sunday the remainder of the day, then you can create two jobs [set to do the same task]. For one give the schedule with time restrictions 00:00 to 13:00. And for the second give time restriction of 22:00 to 23:59.
I hope I understood your problem correctly ...