I am using agendajs to schedule the jobs.
In docs, it is shown how to schedule jobs like
agenda.schedule('in 2 minutes', 'some jobs')
How can I schedule the job in specific date and time.
I tried to use like below but didn't work
agenda.schedule('at 2018-7-24 09:47')
Any help is appreciated. Thanks
As per the docs:
schedule(when, name, [data], [cb])
Schedules a job to run name once at a given time. when can be a Date
or a String such as tomorrow at 5pm.
So something like:
agenda.schedule(new Date(), 'MyJob')
Should do it.
On the end of the day all this is doing is crating the job and setting the nextRunAt ISODate for that job record.
Related
Say for example i want to run a job for a day at "3:22, 4:22, 6:22, 10:22, 18:22, 21.22" on these times just for the current day.
How could we write a cron expresion for it or using other Simple Trigger of Quartz API.
Using cron trigger you can set endAt() to stop trigger at the end of the day
trigger = newTrigger()
.withSchedule(cronSchedule(0 22 3,4,6,10,18,21 ? * * *))
.endAt(TRIGGER_END_TIME)
.forJob(myJobKey)
.build();
I want to schedule the cron job according to the specified time zone. It will fire fine for first time but next time it will not firing according to the specified time zone rather it is firing according to the system's time.
Trigger trigger = TriggerBuilder.newTrigger().withDescription(jobPojo.getDescription()).withIdentity(jobPojo.getTriggerName(), jobPojo.getTriggerGroup())
.withSchedule(CronScheduleBuilder.cronSchedule(jobPojo.getExpression().trim()).inTimeZone(TimeZone.getTimeZone(jobPojo.getTimeZone())).withMisfireHandlingInstructionIgnoreMisfires()).usingJobData(jobDataMap).forJob(jobKey).build();
// As i am passing timezone in json pojo eg: jobPojo.getTimeZone() ="GMT+4:00" which is Dubai timezone Id . my system is running in India.
below is my fetching code :
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Trigger trigger = scheduler.getTrigger(triggerKey);
jobPojo.setNextFireTime(dateFormat.format(trigger.getNextFireTime()));
thanx in advance ..
I have configured jobs with node-cron and yeah I love this node module to schedule job in node.
Here I have requirement of sending push notification to users which are located in different timezone.I want to send notification to them on specific time.
Let's say I am sending notification at 9 PM so in all listed timezone cron job will trigger at 9 PM.
var CronJob = require('cron').CronJob;
var job = new CronJob('00 30 11 * * 1-5', function() {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
}, function () {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
I know all this and I am doing same for one timezone as mentioned in there doc.
timeZone - [OPTIONAL] - Specify the timezone for the execution. This
will modify the actual time relative to your timezone.
But Can I specify multiple timezone here in timezone attribute?
If somebody aware of some other node module can achieve this then let me know?
NOTE : I already know I can configured multiple configuration here for each timezone but what if there are dynamic list.
I don't know of a way to send a list of timezones to the CRON job but you could change the logic in the method that runs inside the cron job.
You could do this :
run the job every half hour
if it's a day you want it to run on
select users where (convert current GMT time to user timezone - if the db can do this) > 11:30 AM in their timezone && hasn't sent a notification yet
send notifications to the returned users.
You might have already gone this route ... just throwing in my 2c
HTH
I have a task which requires to be executed every Thursday, but if the day is a speical holiday such as Christmas, the task should be changed to another day( wednesday or friday), so I get is a general expression plus some special dates, how should I combine all these expressions in one cron expression to be used in Quartz? Thanks.
I don't think you can do it with just one expression since there's no way to specify holidays.
But you can define two triggers T1 and T2 and a "smarter" Job J1:
A trigger T1 on J1 that fires every Thursday using the HolidayCalendar that will exclude arbitrary days from triggering the job execution
//Define an HolidayCalendar and add it to Scheduler
HolidayCalendar cal = new HolidayCalendar();
cal.addExcludedDate( someDate );
sched.addCalendar("myHolidays", cal, false);
//Create the trigger T1 to use the holydayCalendar
...
triggerT1.setCalendarName("myHolidays");
//schedule job with trigger T1
Define a Trigger T2 on J1 that fires on the alterantive day you choose (Wednesday or Friday).
The job J1 must decide whether start executing its business logic or not using the HolydayCalendar. There are many easy ways to do this, for exemple:
//Get Holyday calendar from Scheduler instance
HolidayCalendar cal = sched.getCalendar("myHolidays");
//Decide here if execute or not
if (today is an "alternative" day && lastThursday is an holiday) {
//Job real business logic
}
See this Quartz tutorial for more exemple about Quartz Calendars.
Also you can use this tool to build Quartz-compatible Cron expressions.
Hope this helps!
I want to set up a cron job. The job has to run every 2 days at 1100 hours. The constraint being our server restarts once every day (non negotiable). What should my cron expression be?
I don't think this expression will hold good :
<property name="cronExpression" value="0 0 11 1/2 * ?" />
Any suggestions?
If you want your cron job to be persisted in the store for re-use after program restarts, set volatility of your cron job to TRUE.
In code it should look like this:
//Some code
JobDetail job = new JobDetail(JOBNAME, GROUPNAME, CRONJOB.class);
job.setVolatility(true);
scheduler.scheduleJob(job, trigger);
scheduler.start();
// Some code