Quartz job not getting triggered on the end datetime - quartz-scheduler

I am quite new to Quartz Scheduled jobs. I scheduled on job with a given starttime and endtime.
The job successfully triggers on the starttime and the recurring intervals but on the last recurrence which is equal to the endtime, the job is not triggering anything.
"schedule": {
"startDatetime": 1664457960000,
"endDatetime": 1664717400000,
"recurrenceType": "Interval",
"messageSendTimeZone": "America/Chicago",
"recurrence": "2"
}
I want the job to trigger on all the intervals at the given recurrence.
For eg, if I started the job at 28th Sept who's end time is 2nd Oct, it should trigger on 28th, 30th and 2nd as well.
Is there something that I am missing ?
Thanks,

The endDatetime property indicates when the trigger’s schedule should be canceled.

Related

how to handle user timezone for daylight savings in quartz for cron Triggers?

My service api takes in startDate for quartz Job and day of Month for the job to executed.
Internally, I convert this to cron expression and save in quartz.
For example, a user in PST submits a job request today (Nov 3 2017) as follows.
{
"start": "2017-11-03T18:00:00-07:00",
"dayOfMonth" : 15
}
Here the user wants to schedule a job that fires on 15th of each month at 6 PM, starting from 2017-11-03. so the first-day quartz will fire will be 2017-11-15.
This is how the above request gets converted to cron expression 0 0 18 15 * ? *, which is correct.
Here is how, QRTZ_CRON_TRIGGERS table looks like.
As you notice, time_zone_id is saved as GMT-07:00, but once daylight savings kick-in on Nov 5, it must be GMT-08:00. or else my quartz job will fire one hour earlier. In fact, when I query for nextFireTime, I do get 1510794000000 which is indeed Wednesday November 15, 2017 17:00:00 (pm) in time zone America/Los Angeles (PST)
how do we handle this time_zone_id issue?
P.S: I am using cronTrigger which does not have the notion of preserveHourOfDayAcrossDaylightSavings that is provided by CalendarIntervalTrigger.
Do not use offset to represent the timezone. Rather you can ask the user to pass in timezone like "America/Los_Angeles". Then you can use http://www.quartz-scheduler.org/api/2.2.1/org/quartz/CronScheduleBuilder.html#inTimeZone(java.util.TimeZone) to create trigger with proper timezone.
inTimeZone(TimeZone.getTimeZone("USER_ENTERED_VALUE")
Finally when you look at QRTZ_CRON_TRIGGERS table, the value for TIME_ZONE_ID will be America/Los_Angeles
You can use ZonedDateTime from java8/java8+, In that way you will not need to explicitly convert the given time into server specific time and it also takes care of daylight saving timezones:
protected static Trigger createCronTrigger(String triggerName, ZonedDateTime startTime, String cronExpression, int misFireInstruction, ZoneId timeZone) {
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(triggerName)
.startAt(Date.from(startTime.toInstant())).withSchedule(CronScheduleBuilder.cronSchedule(cronExpression).inTimeZone(TimeZone.getTimeZone(timeZone)).withMisfireHandlingInstructionDoNothing())
.build();
return trigger;
}

Which day is considered as a trigger day for weekly dataset/pipeline?

If I define my dataset/pipeline as weekly -- which day does ADF consider by default provided I am not adding any offset? For Daily and Monthly it's clear to me -- for Monthly for example it is first day of the month and for daily the first hour of the day. So what is that for weekly? Exactly on which day will it get triggered?
And another question -- if I want the pipeline to execute in middle of week every week (e.g. Thursday every week) ?
It uses the ISO standard for week which is Monday.
For the second part of your question then using the offset attribute will deal with this. For example:
"availability": {
"frequency": "Week",
"interval": 1,
"offset": "04.00:00:00",
"style": "StartOfInterval"
}
Hope this helps.

how to fire Quartz Scheduler's cronTrigger every 10 minutes starting at 11am and ending at 3pm everyday?

I'm using "0 0/10 11-15 * * ?" cron expression to fire the trigger. But the trigger is fired even after 3pm.
Try cron "0 0/10 11-14 * * ?". the - in quartz cron expression is used to specify a range. So your cron means the trigger to be fired at 11:00, 12:00, 13:00, 14:00 and 15:00, repeat every 10 minutes and ending at 11:50, 12:50, 13:50, 14:50 and 15:50. That's why it is fired after 3pm.

How to write trigger from given day and given time

Can anybody please tell me how to write a trigger in Quartz Scheduler which starts at Wednesday (17:23:12) and runs till Sunday (20:00:00). I am not sure about no. of repeations.
It's hard to say how you should do this when you aren't sure about the number or timing of the repeats. Knowing that would help decide which type of trigger to use (e.g. CronTrigger vs. SimpleTrigger).
However, regardless of the type of trigger, you would create a Date that is Wednesday at 17:23:12 and set that as the trigger's startTime property, and another Date that is Sunday at 20:00:00 and set that as the trigger's endTime property.
Then if a SimpleTrigger, you would set a repeat interval of XXX and a repeat count of "indefinitely". If a CronTrigger you would set a cron expression that represents the time(s) of day that you want the firing to occur.

How to set workflow condition that runs 2AM everyday?

I am to create email alert which works together with workflow rule.
My goal is to set the workflow that runs 2am everyday &&
my custom object field 'startDate' is tomorrow.
Basically every 2am workflow checks my custom object and see if startDate is tomorrow.
I'm at workflow page looking at Date predefined variable,
I see:
DATE
DATEVALUE
DAY
MONTH
NOW
TODAY
YEAR
For the startDate, I can set condition startDate = today() + 1
For second condition which is 2am everyday I can't think of a way. I don't see HOUR variable etc..
Has anyone done this before?
UPDATE
This might work I have to test though..
Change NOW() datetime output to String (done by TEXT)
Start from index 12 and grab 2 chars to the right (done by MID)
This means I obtained hour part of current time and if the value equals to '02' which means
2am at night.
MID(TEXT(NOW()), 12, 2) = '02'
Wait a sec.. but WHEN does salesforce check this workflow???
If they check workflow once a day, what time it would be? If check is done past 2am, this workflow would never get looked at??? I'm a bit confused.
Work flow only triggers on some event (object update, create, etc.). So having it run at 2am without a some sort of trigger is impossible.
The trick is to use schedulable apex to insert an object (or update a field) every day at 2am and set your workflow to trigger on that insert/update. Then your workflow would fire off on that object at whatever time your scheduled apex ran.