Quartz Cron job required that executes at 12 am every 2 weeks - cron

http://www.cronmaker.com/
I am using the above link and trying to create a cron job which runs at 12AM on the server every 2 weeks. Could anyone help.
Regards
Nikhil

After a google search I found this, maybe it can help you:
https://coderwall.com/p/yzzu5a

Because you've tagged your question with quartz-scheduler, I assume that you are using Quartz.
You can use the CalendarIntervalScheduleBuilder to set an interval of days, weeks, months, etc.
ScheduleBuilder schb = CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInWeeks(2);
Trigger trigger = TriggerBuilder.newTrigger().startAt(DateBuilder.todayAt(0, 0, 0)).withSchedule(schb).forJob(muJob).build();
Here we are telling quartz to run our job every 2 weeks, starting today at 00:00:00 (12 :00 AM ?)
If you insist on using cron style jobs , this might be helpful : http://www.fclose.com/1199/how-to-run-a-cron-job-every-two-weeks-months-days/

Related

Run cron at a different frequency in specific interval

I have a cron job that runs every 30 minutes, starting 10 minutes past a whole hour:
0+10/30+*+*+*+?
Now, this needs to be changed, so that in a specific time interval, it runs every 15 minutes instead. E.g. at 7.50, 8.05, 8.20 and 8.35. Then every 30 minutes again.
Is this possible with a single cron job and if so, how? Or do I need multiple jobs to accomplish this?
Thank you in advance.
not easy in a single cron, and that is also hard to read.
multiple jobs may work fine and show much clear
// This will start at 1:10am, and every 30minutes run once.
0+10/30+1-23/2+*+*+?
// This will start at 0:10am, and every 15minutes run once.
0+10/15+0-24/2+*+*+?
you may also consider to void the two job running at the same time.
As far as I've understood, this is not possible within a single cron job.
setup cron from morning to evening only points out that three different cron jobs are needed, so I am closing my question.

Spring Scheduled job with cron, only for the next 3 days

I am trying to run a method every 10 minutes for the next 3 days and only that.
I have tried this :
cron.expression=0 */10 * * * ?
This will run every 10 minutes every day, every month.
But I only want it to be limited to the next 3 days starting from NOW.
I just can't find how to use (now -> 3 days) in cron
I am using this website and Spring scheduler Spring scheduler doc without success
Based on the Spring specs you can't define this logic directly in to the cron record. You should add such logic in to the program you run with this cron

Hangfire Cron expressions are not valid

I am using Hangfire and I want to describe different scenarios for my RecurringJobs. But I am not being able to achieve what I am looking for, and if CRON is already limited, the CRON used by Hangfire is yet more.
I went on reading Hangfire documentation and I find a like to https://en.wikipedia.org/wiki/Cron#CRON_expression for more complex expressions then the ones supported by default on Hangfire. But they are not even compatible, for instance, Hangfire only has minutes, hour, month, day, days of the week, but if I use the L or the ? on the day like it says on the documentation it does not work. I have this error the following error for this expression 16 14 L ? ?:
InnerException = {"'L' is not a valid [Day] crontab field value. It must be a numeric value between 1 and 31 (all inclusive)."}
CRON from Hangfire has the following method: Monthly(int day); What happens If I choose for instance 31? It will still run on months like February or April for instance at the last day of each month? Or do I need to do something extra to achieve it?
That way what is happening? I do not seem able to define the condition of the day chosen by the user is 31, to run the background jobs always on the last day of the month. And I don't even talk about days 29 or 30 which are also special causes and which I would use always the last day of the month to process the background job.
I though of using the Month method from Hangfire.CRON but I don't think it will treat the days 29,30 and 31 the way I want.
Do you confirm that Hangfire Cron does not use the Cron expressions that are referenced by documentation and if there is any way to achieve what I am looking for? Also, any suggested tutorial or something to help me out? I have been reading https://github.com/atifaziz/NCrontab which I think it is the one Hangfire uses, but it does not help that much.
You are right about NCrontab. Hangfire uses it, so you should ensure your cron expression is supported by this library. Two simple options to do it:
C# Interactive window (as described in NCrontab Readme, or you could use this example )
Online cron visualizer (like https://crontab.guru or http://cron.schlitt.info)
Cron.Monthly(31) is translated to 0 0 31 * * and job would be triggered only if current month has 31 days.
To run the background job always on the last day of the month, add three separate jobs:
0 0 30 4,6,9,11 *
0 0 31 1,3,5,7,8,10,12 *
0 0 28 2 *
Cron job to run on the last day of the month

Creating Cron Expression with of Days and Months Simultaneously

I simply want to create a cron expression that will execute a job after 'N' number of days. Where N can be any number greater than Zero.
So, It's alright if number is between 1 and 30. For Example Cron Expression to Execute Job after each
25 days at 11 AM will be:
0 0 11 1/25 * ? //'?' can only be specfied for Day-of-Month or Day-of-Week.
but if user exceeds this limit so it means we will have to execute job after 'M' months and 'D' days.
I am unable to understand how I can specify both day and month at the same time. Can anyone make me understand how I can create cron expression for this scenario. You may assume job to be execute after each '65' days
thanks for your time.
The short answer is that cron expressions don't support what you want to do. You'll need to pre-process the user's request and convert it into the appropriate cron expression, or implement your own timing routine, which could use cron behind the scene with some extra logic. Another suggestion is to put some restrictions on the user API that will only allow the user to enter cron friendly times like every month, every week, every 3 months, etc.

cron job between 8am and 8pm 4 times at specified intervals of time

i need to run a job 'x' times a day. job timing is every (say 'y' hours) between 8am and 8pm.
i read the documentation of cron between could not figure out how to place the "between times". any suggestion or a good tutorial should be really helpful.i could figure out this much.
Found this in a tutorial. I believe this will serve the requierment
SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger", "triggerGroup-s1");
simpleTrigger.setStartTime(d);
simpleTrigger.setRepeatInterval(1000*60*60*24);
simpleTrigger.setRepeatCount(15);
simpleTrigger.setEndTime(new Date(ctime + 60000L));
simpleTrigger.setPriority(10);
scheduler.scheduleJob(jobDetail, simpleTrigger);
scheduler.start();
how could i modify the expression to serve my purpose.
You have a * in your example where you need to put the start/end hours:
0 8-20/y * * *
Where you replace y with the number of hours you want between runs should be fine. If you have some strange time like "1 hour and 15 minutes between runs", it's going to be a pain - probably just easier to calculate each time and enter it explicitly.
I don't know you can express this in cron expression.
However, you can use multiple Quartz triggers to serve this purpose.

Resources