How to configure Spring sftp:inbound-channel-adapter to run between specific timing lets say 8am-7pm.
Currently i just have the below configuration and i need to poll only between 8am-7pm
<int:poller fixed-rate="300000" max-messages-per-poll="1" />.Heard that Spring batch would help. any suggestions ?
Please, be more specific. Describe your requirements in human words.
E.g. you need to poll every 5 min starting from 8am and ending on 7pm every day.
In this case the cron will look like:
0 0/5 8-19 * *
Related
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
I wonder if it is possible to write an cron expression with several conditions:
Job should be run with given interval in minutes. For example with interval 42 minutes the fire times would be 10:00, 10:42, 11:24, 12:06 and etc.
If the current minute does not end with 0 (e.g. 10:28,10:29), then cron first fire time should be 10:30. So it means that first fire time should have "round" minutes.
I hope that you understand these conditions. Is it possible to describe them with quartz cron?
You can use job trigger like described below in Quartz.net 3.0:
var jobTrigger = TriggerBuilder.Create()
.StartNow()
.WithSimpleSchedule(s => s
.WithIntervalInMinutes(42)
.RepeatForever())
.Build();
And you can restart app at first round time, so it will fire first time at the same time only.
I usually use http://www.cronmaker.com/ to generate my cron expressions. And if you try the every 42 mins option you'll get the following expression: " 0 0/42 * 1/1 * ? *". As for the "round" minutes thing, you can try this when building your trigger:
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity(JobTrigger, JobGroup)
.WithCronSchedule(CroneExpression)
.StartAt(new DateTimeOffset(DateTime.Now,
TimeSpan.FromMinutes(DateTime.Now.Minute % 10)))
.Build();
It is not possible, see for explanation and similar issue: Quartz.net - Repeat on day n, of every m months?
it is also not possible by Cron expressions. To do this, you would need to apply some complex logic, use some operator that is not present in evaluators. Why do you need this? Would you like to combine those 2 requirements and create single complex pattern?
I am using the Quartz Scheduling and I've tried to create a trigger that starts every day at 9 AM until 5 PM, every 25 minutes. It should like that:
9:00, 9:25, 9:50, 10:15, 10:40, 11:05, etc
The final quarts expression looks like that:
0 0/25 9-17 * * ? *
But the execution looks like that:
9:00, 9:25, 9:50, 10:00, 10:25, 10:50, 11:00, etc
There is any way to reach this schedule:
9:00, 9:25, 9:50, 10:15, 10:40, 11:05, etc
or I should change quartz?
Thank you!
Actually this question is similar to Cron expression to be executed every 45 minutes SO question.
Cron expression will not allow you to do that as it defines the exact date and times, when a trigger must be fired. And setup like your actually means "fire every 25 minutes, starting at minute 0 of every hour".
You can achive what you want by using SimpleTrigger with .WithIntervalInMinutes(25) configuration.
SimpleTrigger should meet your scheduling needs if you need to have a job execute exactly once at a specific moment in time, or at a specific moment in time followed by repeats at a specific interval.
P.S. Your cron expression will work for 20 minutes (0 0/20 9-17 * * ? *), as 60 is a multiple of 20. Just in case changing interval is not critical to you)
P.S.2 To be honest you can use Cron expressions if setup few trigger for different intervals, but that is useless. Anyway look onto this SO answer
I have a scenario below and is currently leverage Spring integration as the technology to achieve.
I have around 18000 staff Id data
for each staff, a process needs to kick off to do 1 HTTP call to retrieve staff profile information from mail calender server, then 1 HTTP call to retrieve some other information, then may need to send out 3-5 more HTTP calls in a single task
I need to finish this process for above 50000 staff in 15 mins.
I will need this whole batch process to run every 15mins again and again.
Assume each job takes 5 seconds to finish.. i still need 30 mins to finish
=================
Inital Thinking
I can use spring integration to have something like:
- create one job for each staff - 18000 jobs. The job request likely only contains a staff ID so request is very light weight.
- add all the jobs to the int:queue at once so it triggers the input channel - calenderSynRequestChannel
- have a poller - 100 concurrent workers to clean up the job in 15 mins.
Questions:
it is a good way to do this kind of batch processing? some concerns i have is the size of the queue to support 18000 jobs at once
should I use file base approach to store all the staff id in multiple files and get picked up later by the poller? however, this will also complicate the design as there could have concurrent issue for read/write/delete the files by the workers.
Current solution:
<int:service-activator ref="synCalenderService" method="synCalender" input-channel="calenderSynRequestChannel">
<int:poller fixed-delay="50" time-unit="MILLISECONDS" task-executor="taskExecutor" receive-timeout="0" />
</int:service-activator>
<task:executor id="taskExecutor" pool-size="50" keep-alive="120" queue-capacity="500"/>
Anyone encounters similar problem might give a bit of insight on how to address using Spring Integration
Why not do a spring batch job that:
Reader that reads the staff data
Processor that make the HTTP calls
Writer that writes the result to a logfile (for example)
Then utilize the TaskScheduler (spring batch framework) to schedule execution for every 15 minutes, or maybe even better with a fixed delay.
If you want to do it more in parallel, utilize the org.springframework.batch.integration.async.AsyncItemProcessor (and writer).
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.