With Quartz.Net, Is it possible to list all jobs that will be fired on a specific date? - quartz-scheduler

I'm new to Quartz. I've no idea is there any solution that can get all jobs that will be fired on a specific date?
Say, I created serveral jobs as below:
Job "A" with cron trigger: "0 0 12 1/1 * ? *", which should be fired every day at 12:00.
Job "B" with cron trigger: "0 0 12 ? * MON *", which should be fired every Monday at 12:00.
Job "C" with cron trigger: "0 0 0/1 1/1 * ? *", which should be fired every hour.
Now, is there any solution that can help me get all jobs that will be fire on specific date?
For example:
On next Monday, Job "A", "B" and "C" will be returned. And there should be multiple "C" as it will be fired every hour.
On next Friday, Job "A" and "C" will be returned. And there should be multiple "C" as it will be fired every hour.

If you get an instance of trigger that is used for the job, you can use the following methods defined in ITrigger interface:
// Returns the next time at which the Quartz.ITrigger will fire, after the given
// time. If the trigger will not fire after the given time, null will be returned.
DateTimeOffset? GetFireTimeAfter(DateTimeOffset? afterTime);
// Summary:
// Returns the next time at which the Quartz.ITrigger is scheduled to fire. If the
// trigger will not fire again, null will be returned. Note that the time returned
// can possibly be in the past, if the time that was computed for the trigger to
// next fire has already arrived, but the scheduler has not yet been able to fire
// the trigger (which would likely be due to lack of resources e.g. threads).
//
// Remarks:
// The value returned is not guaranteed to be valid until after the Quartz.ITrigger
// has been added to the scheduler.
DateTimeOffset? GetNextFireTimeUtc();
To get trigger(s) using job name:
JobKey jobKey = new JobKey("<job name>");
var triggers = await scheduler.GetTriggersOfJob(jobKey);

Related

Create agent and give its population different id/names and stop each id delay on different time

I have an agent and set its parameter Name and give 3 different names
What I want to do is stop the delay of each name on a different calendar date. How I can achieve that?
You can get the current year, month and day with the following functions:
int getYear(Date date) — returns the year of the current date.
int getMonth(Date date) — returns the month of the current date: one of the constants JANUARY, FEBRUARY, etc.
int getDayOfMonth(Date date)— returns the day of the month of the current date: 1, 2, …
Based on these, you can get the first agent in the delay block with delay.get(0) and use if function.
Pseudo-code like this;
if (date==x){
if (delay.get(0)==myAgents.get(0)){
stopDelay(delay.get(0));
}
}
or
if (date==x){
if (delay.get(0).Name=="yyy"){
stopDelay(delay.get(0));
}
}

Calculating Time between two events using Siddhi

I am new to CEP and Siddhi. I need to calculate time on task using 2 events.
First event will have {taskId:"100", startTime="2014-11-03T18:35:00.000Z"}
Second event will have {taskId:"100", endTime="2014-11-03T18:35:57.000Z"}
Logic should be for the same taskId do endTime - startTime, will give time on task.
I am struggling to form query that can do this.
Please advice
You can do something like following siddhi query
define stream sensorStream (taskId string, timestamp string);
from every e1=sensorStream -> e2=sensorStream[taskId == e1.taskId]
select e1.taskId,
time:timestampInMilliseconds(e2.timestamp, "yyyy-MM-dd HH:mm:ss")
- time:timestampInMilliseconds(e1.timestamp, "yyyy-MM-dd HH:mm:ss")
as duration
insert into outputStream;
Here i have done a pattern matching [1] to catch sequence of occurring of 2 events of same task ID, then those 2 events will be assigned to e1 and e2 respectively. Finally inside select, e2.timestamp and e1.timestamp and string values will be converted to milliseconds using time extensions timestampInMilliseconds function [2] and subtracted e1 timestamp value from e2 timestamp to get the duration
[1] https://docs.wso2.com/display/CEP420/SiddhiQL+Guide+3.1#SiddhiQLGuide3.1-Pattern
[2] https://docs.wso2.com/display/CEP420/Time+Extension#TimeExtension-TimestampInMillisecondsfunction

Kendo UI Scheduler - Check is date in recurrence rule

I have recurrence rule(for example like "FREQ=WEEKLY;BYDAY=WE"), start date and end date.
Where can I find method or function to check is current date enters in my rule or not?
For example if I have:
Start date: 01.02.2017
End date: 03.02.2017
Recurrence rule: "FREQ=DAILY;NTERVAL=5"
So, in this case date 4.02.2017 not enters in this rule, but date 5.02.2017 enters in this rule.
You can use the scheduler's occurrencesInRange method like this:
var scheduler = $("#scheduler").data("kendoScheduler");
var events = scheduler.occurrencesInRange(
new Date("2017-02-05"), // The date you want to check at 0:00 am
new Date("2017-02-06") // The same date + 24 hours
);
You'll get a list of recurring dates in that date. If the array isn't empty then the start date you supplied the above method has an occurance in it.

Setting quartz schedule with startdate and timezone

I have the following method to schedule a job to fired at different timezone and start date.
If the server's timezone is Asia/Taipei, and the schedule is set to the following inputs:
triggerName="testTrigger",
jobName="testJob",
group="testGroup",
startDate = 2014-12-03 18:00:00
timezoneString = "Austrailia/Melbourne"
cronExp = 0 0/1 * 1/1 * ? *
When should be the firing time?
public void schedule(String triggerName, String jobName, String group, Date startDate, String timezoneString, String cronExp){
try {
JobDetail jobDetail = new JobDetail(jobName, group, MessageJob.class);
TimeZone timeZone = TimeZone.getTimeZone(timezoneString);
Date startDate = startDate;
Calendar cal1 = Calendar.getInstance();
cal1.setTime(startDate);
cal1.setTimeZone(timeZone);
startDate = cal1.getTime();
CronTrigger cronTrigger = new CronTrigger(triggerName, group, jobName, jobGroup, startDate, null, cronExp, timeZone);
scheduler.start();
} catch (ParseException e) {
System.out.println("ParseException issues " + e.getMessage());
}catch(IllegalArgumentException e){
System.out.println("IllegalArgumentException issues " + e.getMessage());
}
}
If you explicitely set a different timezone in a Quartz cron trigger, then the trigger will fire according to the trigger configuration in the specified time zone. I.e. your cron trigger expresion will be evaluated using the Australia/Melbourne timezone.
To prove this, I created a sample cron trigger with the Australia/Melbourne time zone in QuartzDesk. My local timezone is CET (Central European Time). In the GUI you can clearly see that the trigger's next fire time as returned by Quartz is 2014-12-04 14:00:00 (in the local CET time zone).
Now when you convert this time to the Australia/Melbourne timezone (I use this online converter), I get 2014-12-04 00:00:00 which is the expected trigger time:
As for when your cron expression (0 0/1 * 1/1 * ? *) fires, it fires every minute on every hour (01:00:00, 01:01:00,...) in the Australia/Melbourne timezone. Now considering that Taipei is Australia/Melbourne + 3 hours, then the fire times in your timezone will be 21:01:00, 21:02:00, ...

Merge a Date object which has 04:00 as its time with another time string ("8:30am") into a new Date object

I have a mongo db with a document that has a date and a time separately.
Date object was intended to be just a date, so it has the time as
04:00 (time-zone adjusted to -4)
db.logs.findOne().date
ISODate("2014-08-05T04:00:00Z")
And there's a separate time field which is still a string
db.logs.findOne().time
8:30am
How do I merge them both into one field?
Do the combination client-side, using appropriate libraries to handle calendar and clock calculations, and then update/insert the document. MongoDB (as of 2.6, anyway) doesn't have facilities for updating to the combination server side.
db.logs.find().forEach(function(log) {
log.date = new Date(log.date.getFullYear(),
/* date */ log.date.getMonth(),
log.date.getDate(),
/* time */ parseInt(log.time)
/* + 12 if PM */ + (((log.time.charAt(log.time.length - 2) + log.time.charAt(log.time.length - 1)) === 'pm') ? 12 : 0));
db.logs.save(log);
})